Programmatic login not working in 5.1

Posted by Community Admin on 03-Aug-2018 21:00

Programmatic login not working in 5.1

All Replies

Posted by Community Admin on 20-Feb-2013 00:00

I was using a programmatic login in Sitefinity 4. However, after switching to version 5, it doesn't work anymore. Can I please be shown how to change this to get this functioning again? My code is below:


protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    
        Credentials credentials = new Credentials();
        credentials.UserName = Login1.UserName;
        credentials.Password = Login1.Password;
        credentials.Persistent = Login1.RememberMeSet;
        credentials.MembershipProvider = "HCDBMembership";
        UserLoggingReason reason = SecurityManager.AuthenticateUser(credentials);
        if (reason.ToString() == "UserAlreadyLoggedIn")
        
            SecurityManager.Logout("HCDBMembership", Login1.UserName, credentials);
            reason = SecurityManager.AuthenticateUser(credentials);
 
        
        if (reason.ToString() == "Success")
        
 
            UserManager usrMngr = UserManager.GetManager("HCDBMembership");
             
            usrMngr.Provider.SuppressSecurityChecks = true;
            usrMngr.SaveChanges();
 
            System.Web.Security.FormsAuthentication.SetAuthCookie(Login1.UserName, Login1.RememberMeSet);
 
            e.Authenticated = true;
            if (Authenticated != null)
            
                Authenticated(this, new EventArgs());
            
        
        else
        
        
    

Posted by Community Admin on 04-Mar-2013 00:00

Hello again,

Is there any solution to this problem?

I'll just say I really don't appreciate having to constantly debug things like this every time we upgrade to another version of Sitefinity.

If you would please inform me of the mystery line of code that apparently makes this work. Thanks.

Posted by Community Admin on 07-Mar-2013 00:00

Hello,

 In 5.1 you can authenticate a user by simply calling SecurityManager.AuthenticateUser(); and using one of the available overloads. It automatically creates the cookie.

Kind regards,
Atanas Valchev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 12-Mar-2013 00:00

And as you've probably realized, I already knew that, and it didn't work anyway. We've already submitted a support ticket regarding this issue. Thanks anyway.

This thread is closed