public void GetPassword() { byte[] password = ASCIIEncoding.ASCII.GetBytes("zab123"); manager.CreateUser(userName, password); byte[] result = manager.GetPassword(userName); Assert.AreEqual(result.Length, password.Length); manager.DeleteUser(userName); }
public int ChangePwd(string oldPwd, string newPwd) { try { byte[] realUserPwd = manager.GetPassword(Thread.CurrentPrincipal.Identity.Name); byte[] userPassword = new SHA1Managed().ComputeHash( ASCIIEncoding.ASCII.GetBytes(oldPwd)); if (!Convert.ToBase64String(userPassword).Equals (Convert.ToBase64String(realUserPwd))) { return(-1); } manager.ChangeUserPassword(Thread.CurrentPrincipal.Identity.Name, new SHA1Managed().ComputeHash(ASCIIEncoding.ASCII.GetBytes(newPwd))); return(0); } catch (Exception ex) { throw ex; } }
/// <devdoc> /// Compares the password passed in against the password stored in the database. /// </devdoc> private bool PasswordsMatch(byte[] password, string userName) { DbAuthenticationProviderData dbAuthenticationProviderData = (DbAuthenticationProviderData)securityConfigurationView.GetAuthenticationProviderData(ConfigurationName); bool result = false; UserRoleManager manager = new UserRoleManager(dbAuthenticationProviderData.Database, securityConfigurationView.ConfigurationContext); byte[] hashedPassword = manager.GetPassword(userName); if (hashedPassword != null) { HashProviderFactory hashFactory = new HashProviderFactory(securityConfigurationView.ConfigurationContext); IHashProvider hashProvider = hashFactory.CreateHashProvider(dbAuthenticationProviderData.HashProvider); result = hashProvider.CompareHash(password, hashedPassword); } return(result); }
private void GetPasswordDelegate(params object[] methodParams) { manager.GetPassword((string)methodParams[0]); }
/// <devdoc> /// Compares the password passed in against the password stored in the database. /// </devdoc> private bool PasswordsMatch(byte[] password, string userName) { DbAuthenticationProviderData dbAuthenticationProviderData = (DbAuthenticationProviderData)securityConfigurationView.GetAuthenticationProviderData(ConfigurationName); bool result = false; UserRoleManager manager = new UserRoleManager(dbAuthenticationProviderData.Database, securityConfigurationView.ConfigurationContext); byte[] hashedPassword = manager.GetPassword(userName); if (hashedPassword != null) { HashProviderFactory hashFactory = new HashProviderFactory(securityConfigurationView.ConfigurationContext); IHashProvider hashProvider = hashFactory.CreateHashProvider(dbAuthenticationProviderData.HashProvider); result = hashProvider.CompareHash(password, hashedPassword); } return result; }