/// <summary> /// Processes a request to update the password for a membership user. /// </summary> /// <param name="username">The user to update the password for.</param> /// <param name="oldPassword">The current password for the specified user.</param> /// <param name="newPassword">The new password for the specified user.</param> /// <returns> /// true if the password was updated successfully; otherwise, false. /// </returns> public override bool ChangePassword(string username, string oldPassword, string newPassword) { Business.UserDataService userData = new UserDataService(_currentUser, _userDao, _properties); userData.UserName = username; userData.Password = oldPassword; if (userData.ValidateUser(oldPassword)) { return(false); } ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, newPassword, true); OnValidatingPassword(args); if (args.Cancel) { if (args.FailureInformation != null) { throw args.FailureInformation; } else { throw new MembershipPasswordException("Change password canceled due to new password validation failure."); } } CustomMembershipUser customUser = new CustomMembershipUser(userData); return(customUser.ChangePassword(oldPassword, newPassword)); }
/// <summary> /// Adds a new membership user to the data source. /// </summary> /// <param name="username">The user name for the new user.</param> /// <param name="password">The password for the new user.</param> /// <param name="email">The e-mail address for the new user.</param> /// <param name="passwordQuestion">The password question for the new user.</param> /// <param name="passwordAnswer">The password answer for the new user</param> /// <param name="isApproved">Whether or not the new user is approved to be validated.</param> /// <param name="providerUserKey">The unique identifier from the membership data source for the user.</param> /// <param name="status">A <see cref="T:System.Web.Security.MembershipCreateStatus"/> enumeration value indicating whether the user was created successfully.</param> /// <returns> /// A <see cref="T:System.Web.Security.MembershipUser"/> object populated with the information for the newly created user. /// </returns> public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true); OnValidatingPassword(args); if (args.Cancel) { status = MembershipCreateStatus.InvalidPassword; return(null); } UserDataService user = new UserDataService(_currentUser, _userDao, _properties); user.UserName = username; user.Password = password; user.Email = email; user.PasswordQuestion = passwordQuestion; user.PasswordAnswer = passwordAnswer; user.IsApproved = isApproved; CustomMembershipUser customUser = new CustomMembershipUser(user); status = user.CreateUser(); return(GetUser(username, false)); }
/// <summary> /// Clears a lock so that the membership user can be validated. /// </summary> /// <param name="userName">The membership user whose lock status you want to clear.</param> /// <returns> /// true if the membership user was successfully unlocked; otherwise, false. /// </returns> public override bool UnlockUser(string userName) { Business.UserDataService userData = new UserDataService(_currentUser, _userDao, _properties); userData.UserName = userName; CustomMembershipUser customUser = new CustomMembershipUser(userData); return(customUser.UnlockUser()); }
/// <summary> /// Resets a user's password to a new, automatically generated password. /// </summary> /// <param name="username">The user to reset the password for.</param> /// <param name="answer">The password answer for the specified user.</param> /// <returns>The new password for the specified user.</returns> public override string ResetPassword(string username, string answer) { Business.UserDataService userData = new UserDataService(_currentUser, _userDao, _properties); userData.UserName = username; userData.PasswordAnswer = answer; CustomMembershipUser customUser = new CustomMembershipUser(userData); if (!_properties.EnablePasswordReset) { throw new NotSupportedException("Password reset is not enabled."); } if (answer == null && _properties.RequiresQuestionAndAnswer) { //UpdateFailureCount(username, FailureType.PasswordAnswer); throw new ProviderException("Password answer required for password reset."); } string newPassword = System.Web.Security.Membership.GeneratePassword( _properties.MinRequiredPasswordLength, _properties.MinRequiredNonAlphanumericCharacters); ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, newPassword, true); OnValidatingPassword(args); if (args.Cancel) { if (args.FailureInformation != null) { throw args.FailureInformation; } else { throw new MembershipPasswordException("Reset password canceled due to password validation failure."); } } return(customUser.ResetPassword(answer)); }
/// <summary> /// Processes a request to update the password question and answer for a membership user. /// </summary> /// <param name="username">The user to change the password question and answer for.</param> /// <param name="password">The password for the specified user.</param> /// <param name="newPasswordQuestion">The new password question for the specified user.</param> /// <param name="newPasswordAnswer">The new password answer for the specified user.</param> /// <returns> /// true if the password question and answer are updated successfully; otherwise, false. /// </returns> public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer) { Business.UserDataService userData = new UserDataService(_currentUser, _userDao, _properties); userData.UserName = username; userData.Password = password; userData.PasswordQuestion = newPasswordQuestion; userData.PasswordAnswer = newPasswordAnswer; if (!userData.ValidateUser(password)) { return(false); } CustomMembershipUser customUser = new CustomMembershipUser(userData); return(customUser.ChangePasswordQuestionAndAnswer(password, newPasswordQuestion, newPasswordAnswer)); }
/// <summary> /// Gets the password for the specified user name from the data source. /// </summary> /// <param name="username">The user to retrieve the password for.</param> /// <param name="answer">The password answer for the user.</param> /// <returns> /// The password for the specified user name. /// </returns> public override string GetPassword(string username, string answer) { string password = string.Empty; Business.UserDataService userData = new UserDataService(_currentUser, _userDao, _properties); userData.UserName = username; userData.PasswordAnswer = answer; if (!_properties.EnablePasswordRetrieval) { throw new ProviderException("Password Retrieval Not Enabled."); } if (_properties.PasswordFormat == MembershipPasswordFormat.Hashed) { throw new ProviderException("Cannot retrieve Hashed passwords."); } CustomMembershipUser customUser = new CustomMembershipUser(userData); password = customUser.GetPassword(answer); //if (_properties.RequiresQuestionAndAnswer && !CheckPassword(answer, passwordAnswer)) //{ // UpdateFailureCount(username, FailureType.PasswordAnswer); // throw new MembershipPasswordException("Incorrect password answer."); //} //if (_properties.PasswordFormat == MembershipPasswordFormat.Encrypted) //{ // password = UnEncodePassword(password); //} return(password); }
/// <summary> /// Updates information about a user in the data source. /// </summary> /// <param name="user">A <see cref="T:System.Web.Security.MembershipUser"/> object that represents the user to update and the updated information for the user.</param> public override void UpdateUser(MembershipUser user) { CustomMembershipUser customUser = (CustomMembershipUser)user; customUser.UserData.UpdateUser(); }