public static bool setUserPassword(this TM_UserData userData, TMUser tmUser, string currentPassword, string newPassword) { //var tmUser = tmAuthentication.currentUser; if (tmUser.notNull()) { if (tmUser.SecretData.PasswordHash == tmUser.createPasswordHash(currentPassword)) // check if current password matches provided value { var newPasswordHash = tmUser.createPasswordHash(newPassword); if (newPasswordHash != tmUser.SecretData.PasswordHash) // check that password are not repeated { tmUser.logUserActivity("User Password Change", "With previous password provided"); return(tmUser.setPasswordHash(newPasswordHash)); } } } return(false); }
public static ChangePassword_Result setUserPasswordResponse(this TM_UserData userData, TMUser tmUser, string currentPassword, string newPassword) { //var tmUser = tmAuthentication.currentUser; if (tmUser.notNull()) { if (tmUser.SecretData.PasswordHash == tmUser.createPasswordHash(currentPassword)) // check if current password matches provided value { var newPasswordHash = tmUser.createPasswordHash(newPassword); if (newPasswordHash != tmUser.SecretData.PasswordHash) // check that password are not repeated { tmUser.logUserActivity("User Password Change", "With previous password provided"); if (newPassword.Length < 8 || newPassword.Length > 256) { return(ValidatePasswordLength()); } //Password Complexity chechek if (!Regex.IsMatch(newPassword, ValidationRegex.PasswordComplexity)) { tmUser.logUserActivity("User Password Change", "Your password should be at least 8 characters long. It should have one uppercase and one lowercase letter, a number and a special character."); return(ValidatePasswordComplexity()); } var result = tmUser.setPasswordHash(newPasswordHash); if (result) { return new ChangePassword_Result { PasswordChanged = true, Message = "" } } ; return(new ChangePassword_Result { PasswordChanged = false, Message = TMConsts.DEFAULT_PASSWORD_CHANGE_ERROR_MESSAGE }); } tmUser.logUserActivity("User Password Change", "Current Password and New Password are equals"); return(CurrentPasswordAndNewPasswordAreEqualsResponse()); } tmUser.logUserActivity("User Password Change", "Current Password does not match provided value"); return(CurrentPasswordDoNotMatchResponse()); } return(new ChangePassword_Result()); }
public static ChangePassword_Result setUserPasswordResponse(this TM_UserData userData, TMUser tmUser, string currentPassword, string newPassword) { //var tmUser = tmAuthentication.currentUser; if (tmUser.notNull()) { if (tmUser.SecretData.PasswordHash == tmUser.createPasswordHash(currentPassword)) // check if current password matches provided value { var newPasswordHash = tmUser.createPasswordHash(newPassword); if (newPasswordHash != tmUser.SecretData.PasswordHash) // check that password are not repeated { tmUser.logUserActivity("User Password Change", "With previous password provided"); if (newPassword.Length < 8 || newPassword.Length > 256) { return ValidatePasswordLength(); } //Password Complexity chechek if (!Regex.IsMatch(newPassword, ValidationRegex.PasswordComplexity)) { tmUser.logUserActivity("User Password Change", "Your password should be at least 8 characters long. It should have one uppercase and one lowercase letter, a number and a special character."); return ValidatePasswordComplexity(); } var result = tmUser.setPasswordHash(newPasswordHash); if (result) return new ChangePassword_Result {PasswordChanged = true, Message = ""}; return new ChangePassword_Result { PasswordChanged = false, Message = TMConsts.DEFAULT_PASSWORD_CHANGE_ERROR_MESSAGE }; } tmUser.logUserActivity("User Password Change", "Current Password and New Password are equals"); return CurrentPasswordAndNewPasswordAreEqualsResponse(); } tmUser.logUserActivity("User Password Change", "Current Password does not match provided value"); return CurrentPasswordDoNotMatchResponse(); } return new ChangePassword_Result(); }
public static bool setUserPassword(this TM_UserData userData, TMUser tmUser, string currentPassword, string newPassword) { //var tmUser = tmAuthentication.currentUser; if (tmUser.notNull()) { if (tmUser.SecretData.PasswordHash == tmUser.createPasswordHash(currentPassword)) // check if current password matches provided value { var newPasswordHash = tmUser.createPasswordHash(newPassword); if (newPasswordHash != tmUser.SecretData.PasswordHash) // check that password are not repeated { tmUser.logUserActivity("User Password Change", "With previous password provided"); return tmUser.setPasswordHash(newPasswordHash); } } } return false; }