Hello,
I have imported my old users into CMSUsers. I have added the following loader attribute:
public override void Init() { SecurityEvents.Authenticate.Execute += OnAuthenticateExecute; } private void OnAuthenticateExecute(object sender, AuthenticationEventArgs e) { try { UserInfo objUserInfo = UserInfoProvider.GetUserInfo(e.UserName); if (objUserInfo == null) return; // user doesn't exist bool blnIsImportedUser = objUserInfo.GetValue<bool>("IsImportedUser", false); // is this an imported user? if (blnIsImportedUser) { string strEncryptedPassword = objUserInfo.GetValue<string>("ImportedEncryptedPassword", string.Empty); // get the imported password string strPasswordSalt = objUserInfo.GetValue<string>("ImportedPasswordSalt", string.Empty); // get the imported salt if (string.IsNullOrWhiteSpace(strEncryptedPassword) || string.IsNullOrWhiteSpace(strPasswordSalt)) return; // pass and/or salt not set ImportedAuthentication objImportedAuth = new ImportedAuthentication(); // use old authentication if (strEncryptedPassword.Equals(objImportedAuth.EncodePassword(e.Password, strPasswordSalt))) // is password correct? { UserInfoProvider.SetPassword(objUserInfo, e.Password); // set the kentico password to the same as the user enty objUserInfo.SetValue("IsImportedUser", false); // remove old user flag objUserInfo.Update(); // save to kentico } } } catch (Exception ex) { ErrorHandler.HandleError(ex); } }
When an imported user attempts to log in, the code acts as expected. The kentico password is set and the flag is unset. However the authentication fails. On the next attempt, the authentication is successful. My guess is the authentication has already failed before it gets to my code. Is there a way of changing the password before kentico authenticates the user?
Thanks
After your .Update() call, authenticate the user again. Your code should not run again since your flag is set to false.
How do you do the authentication again? The user is going via the normal kentico login page.
AuthenticationHelper.AuthenticateUser(userName, true);
Still have the same problem. Click login the first time it says login failed. Click again using the same password it logs in.
Please, sign in to be able to submit a new answer.