/// <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> /// Removes a user from the membership data source. /// </summary> /// <param name="username">The name of the user to delete.</param> /// <param name="deleteAllRelatedData">true to delete data related to the user from the database; false to leave data related to the user in the database.</param> /// <returns> /// true if the user was successfully deleted; otherwise, false. /// </returns> public override bool DeleteUser(string username, bool deleteAllRelatedData) { Business.UserDataService userData = new UserDataService(_currentUser, _userDao, _properties); userData.UserName = username; return(userData.DeleteUser(deleteAllRelatedData)); }
/// <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> /// Gets information from the data source for a user. Provides an option to update the last-activity date/time stamp for the user. /// </summary> /// <param name="username">The name of the user to get information for.</param> /// <param name="userIsOnline">true to update the last-activity date/time stamp for the user; false to return user information without updating the last-activity date/time stamp for the user.</param> /// <returns> /// A <see cref="T:System.Web.Security.MembershipUser"/> object populated with the specified user's information from the data source. /// </returns> public override MembershipUser GetUser(string username, bool userIsOnline) { int errorNumber = 0; string errorDescription = null; Model.UserData userData = _userManagerDao.GetUser(_currentUser, username, false, userIsOnline, out errorNumber, out errorDescription); if (errorNumber != 0 || !string.IsNullOrEmpty(errorDescription)) { LogManager.WriteWarning(_currentUser, this, "User " + username + " cannot be loaded.", errorDescription); return(null); } if (userData == null) { LogManager.WriteWarning(_currentUser, this, "User " + username + " cannot be loaded.", null); return(null); } else { LogManager.WriteTrace(_currentUser, this, "User " + username + " was loaded.", null); } Business.UserDataService userService = new UserDataService(_currentUser, userData, _userDao, _properties); return(new CustomMembershipUser(userService)); }
/// <summary> /// Verifies that the specified user name and password exist in the data source. /// </summary> /// <param name="username">The name of the user to validate.</param> /// <param name="password">The password for the specified user.</param> /// <returns> /// true if the specified username and password are valid; otherwise, false. /// </returns> public override bool ValidateUser(string username, string password) { Business.UserDataService user = new UserDataService(_currentUser, _userDao, _properties); user.UserName = username; user.Password = password; return(user.ValidateUser(password)); }
/// <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()); }
private MembershipUserCollection ConverToUserCollection(IList <Model.UserData> list) { MembershipUserCollection collection = new MembershipUserCollection(); foreach (Model.UserData user in list) { Business.UserDataService userService = new UserDataService(_currentUser, user, _userDao, _properties); collection.Add(new CustomMembershipUser(userService)); } return(collection); }
public CustomMembershipUser(Model.UserData userData) : base(System.Web.Security.Membership.Provider.Name, userData.UserName, userData.UserName, userData.Email, userData.PasswordQuestion, userData.Comments, userData.IsApproved, userData.IsLockedOut, userData.CreatedDate, userData.LastLoginDate, userData.LastActivityDate, userData.LastPasswordChangedDate, userData.LastLockoutDate) { DataAccess.IUserDao userDao = new DataAccess.SQLSupport.UserDataDao(); Business.UserDataService userService = new UserDataService(System.Web.HttpContext.Current.User.Identity.Name, userData, userDao, new Model.SystemProperties()); _userData = userService; }
/// <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); }