Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Biagio Paruolo 1594 posts 1825 karma points c-trib
    Nov 29, 2015 @ 14:54
    Biagio Paruolo
    0

    Member login: programmatically logon. How to?

    How to login a member via API that is passing login and password ( hashed ) via code and not input from user?

  • Marc Goodson 2141 posts 14324 karma points MVP 8x c-trib
    Nov 29, 2015 @ 22:11
    Marc Goodson
    0

    Hi Biagio

    If your code is in a macro partial view or controller or class inheriting from one of the special Umbraco base controllers / classes eg SurfaceController

    Then you will have access to the MembershipHelper helpers via the Members instance.

    https://our.umbraco.org/documentation/Reference/Querying/MemberShipHelper/

    and therefore:

    Members.Login("username", "password");
    

    should do it!

    If you are in a custom class you can create a reference to the MembershipHelper using:

    var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(Umbraco.Web.UmbracoContext.Current);
    

    regards

    Marc

  • Biagio Paruolo 1594 posts 1825 karma points c-trib
    Nov 29, 2015 @ 22:42
    Biagio Paruolo
    0

    Hi, Marc,

    Thank you. The problem is if the password is hashed.

  • Marc Goodson 2141 posts 14324 karma points MVP 8x c-trib
    Nov 30, 2015 @ 09:12
    Marc Goodson
    1

    Ahh Biagio I see;

    So do you need to know, given that you have the hash, how to compare this hash to the entry in the database table ?

    or are you pretty much at the stage where you just want to log the person in ?

    If so I have a feeling:

    FormsAuthentication.RedirectFromLoginPage("username", false);
    

    or

    FormsAuthentication.SetAuthCookie("username", false);
    

    will create the authentication cookie for the user, and it will be as if they just logged in.

  • Biagio Paruolo 1594 posts 1825 karma points c-trib
    Nov 30, 2015 @ 10:06
    Biagio Paruolo
    0

    I'll try...I need to logon the user because he logon with social network before. I explain better.

    1 - the admin register the user 2 - after the user can choose to enable the login with social network so I need to create a Wizard to memorize social network ID + token. 3 - after he can login or with social or normal

  • Matthieu Nelmes 102 posts 385 karma points
    Nov 30, 2015 @ 10:52
    Matthieu Nelmes
    0

    Marc was bang on the money, you need to set the AuthCookie session wih:

    System.Web.Security.FormsAuthentication.SetAuthCookie('Username', true);
    

    Once I've tidied my code I'll post a full example

  • Matthieu Nelmes 102 posts 385 karma points
    Nov 30, 2015 @ 10:59
Please Sign in or register to post replies

Write your reply to:

Draft