public override string ResetPassword(string username, string answer) { if (!EnablePasswordReset) { throw new NotSupportedException(); } using (var transaction = new TransactionScope(_mConfiguration)) { var dataStore = new UserDataStore(transaction); User user = dataStore.FindByName(ApplicationName, username); if (user == null) { throw new UserNotFoundException(username); } if (RequiresQuestionAndAnswer && user.ValidatePasswordAnswer(answer, PasswordAttemptWindow, MaxInvalidPasswordAttempts) == false) { transaction.Commit(); throw new MembershipPasswordException(); } else { string newPassword = System.Web.Security.Membership.GeneratePassword(MinRequiredPasswordLength, MinRequiredNonAlphanumericCharacters); user.ChangePassword(newPassword); transaction.Commit(); return(newPassword); } } }
public override bool ChangePassword(string username, string oldPassword, string newPassword) { try { ValidatePassword(username, newPassword, false); using (var transaction = new TransactionScope(_mConfiguration)) { var dataStore = new UserDataStore(transaction); User user = dataStore.FindByName(ApplicationName, username); if (user == null) { throw new UserNotFoundException(username); } if (user.CheckPassword(oldPassword) == false) { throw new UserNotFoundException(username); } user.ChangePassword(newPassword); transaction.Commit(); } return(true); } catch (Exception ex) { LogException(ex, "ChangePassword"); return(false); } }
/// <summary> /// /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="email"></param> /// <param name="passwordQuestion"></param> /// <param name="passwordAnswer"></param> /// <param name="isApproved"></param> /// <param name="providerUserKey">Not used</param> /// <param name="status"></param> /// <returns></returns> public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { try { //Validate password ValidatePassword(username, password, true); using (var transaction = new TransactionScope(_mConfiguration)) { var dataStore = new UserDataStore(transaction); //Check name if (dataStore.FindByName(ApplicationName, username) != null) { status = MembershipCreateStatus.DuplicateUserName; return(null); } //Check email if (RequiresUniqueEmail) { if (string.IsNullOrEmpty(email)) { status = MembershipCreateStatus.InvalidEmail; return(null); } if (dataStore.FindByEmail(ApplicationName, email).Count > 0) { status = MembershipCreateStatus.DuplicateEmail; return(null); } } var user = new User(ApplicationName, username); user.Email = email; user.ChangePassword(password); user.ChangePasswordQuestionAnswer(passwordQuestion, passwordAnswer); user.Enabled = isApproved; dataStore.Insert(user); transaction.Commit(); status = MembershipCreateStatus.Success; return(UserToMembershipUser(user)); } } catch (CodeInvalidCharsException ex) //this exception is caused by an invalid user Name { LogException(ex, "CreateUser"); status = MembershipCreateStatus.InvalidUserName; return(null); } catch (MembershipPasswordException ex) { LogException(ex, "CreateUser"); status = MembershipCreateStatus.InvalidPassword; return(null); } catch (Exception ex) { LogException(ex, "CreateUser"); status = MembershipCreateStatus.ProviderError; return(null); } }