Copied to clipboard

Flag this post as spam?

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


  • Ryan 34 posts 138 karma points
    Apr 13, 2015 @ 11:32
    Ryan
    1

    Create member then login programmatically

    Hi all,

    As the topic title says, I'm trying to create a member and then login programmatically.It would seem that when I call the ValidateUser function it can't login the newly created member and always returns false. The reason I'm trying to do this is because we currently authenticate via an external service - I then create a one time member login that get's deleted once the session ends.

    Any help is greatly appreciated - code snippet below.

    var memberService = Services.MemberService;
    //create umbraco member and set the password as a random Guid
    var member = CreateUmbracoMember();
    if(memberService.Exists(member.Id))
    {
      if (Membership.ValidateUser(member.Username, member.RawPasswordValue))
      {
       //Always returns false
      }
    }
    
  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Apr 13, 2015 @ 12:05
    Jeroen Breuer
    3

    Hello,

    You can login a member programmatically by doing the following:

    System.Web.Security.FormsAuthentication.SetAuthCookie(email, true);

    Jeroen

  • Ryan 34 posts 138 karma points
    Apr 13, 2015 @ 13:03
    Ryan
    0

    That did the job, thanks!

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Apr 13, 2015 @ 13:17
    Jeroen Breuer
    0

    Glad I could help. Can you please mark a post as the solution.

    Jeroen

  • James Jackson-South 489 posts 1747 karma points c-trib
    Apr 13, 2015 @ 15:40
    James Jackson-South
    1

    On a SurfaceController there is also the property Members which represents an instance of Umbraco.Web.Security.MembershipHelper

    if(this.Members.Login(model.Username, model.Password)){
    
        // Do what you want.
    }
    
  • Biagio Paruolo 1618 posts 1910 karma points c-trib
    Nov 29, 2015 @ 15:00
    Biagio Paruolo
    0

    this is for the password in clear mode. How solve for hashed password?

Please Sign in or register to post replies

Write your reply to:

Draft