diff --git a/src/Umbraco.Core/Security/MembershipProviderBase.cs b/src/Umbraco.Core/Security/MembershipProviderBase.cs index 3c7a1664f8..85af50a922 100644 --- a/src/Umbraco.Core/Security/MembershipProviderBase.cs +++ b/src/Umbraco.Core/Security/MembershipProviderBase.cs @@ -3,6 +3,7 @@ using System.Collections.Specialized; using System.Configuration.Provider; using System.Security.Cryptography; using System.Text; +using System.Text.RegularExpressions; using System.Web.Configuration; using System.Web.Hosting; using System.Web.Security; @@ -213,6 +214,58 @@ namespace Umbraco.Core.Security } + /// + /// Override this method to ensure the password is valid before raising the event + /// + /// + protected override void OnValidatingPassword(ValidatePasswordEventArgs e) + { + var attempt = IsPasswordValid(e.Password, MinRequiredNonAlphanumericCharacters, PasswordStrengthRegularExpression, MinRequiredPasswordLength); + if (attempt.Success == false) + { + e.Cancel = true; + return; + } + + base.OnValidatingPassword(e); + } + + protected internal enum PasswordValidityError + { + Ok, + Length, + AlphanumericChars, + Strength + } + + protected internal Attempt IsPasswordValid(string password, int minRequiredNonAlphanumericChars, string strengthRegex, int minLength) + { + if (minRequiredNonAlphanumericChars > 0) + { + var nonAlphaNumeric = Regex.Replace(password, "[a-zA-Z0-9]", "", RegexOptions.Multiline | RegexOptions.IgnoreCase); + if (nonAlphaNumeric.Length < minRequiredNonAlphanumericChars) + { + return Attempt.Fail(PasswordValidityError.AlphanumericChars); + } + } + + if (string.IsNullOrEmpty(strengthRegex) == false) + { + if (Regex.IsMatch(password, strengthRegex, RegexOptions.Compiled) == false) + { + return Attempt.Fail(PasswordValidityError.Strength); + } + + } + + if (password.Length < minLength) + { + return Attempt.Fail(PasswordValidityError.Length); + } + + return Attempt.Succeed(PasswordValidityError.Ok); + } + /// /// Gets the name of the default app. /// diff --git a/src/Umbraco.Web.UI/umbraco/controls/PasswordChanger.ascx.cs b/src/Umbraco.Web.UI/umbraco/controls/PasswordChanger.ascx.cs index 7e6b19c470..a42e5b3ca1 100644 --- a/src/Umbraco.Web.UI/umbraco/controls/PasswordChanger.ascx.cs +++ b/src/Umbraco.Web.UI/umbraco/controls/PasswordChanger.ascx.cs @@ -13,6 +13,12 @@ namespace Umbraco.Web.UI.Umbraco.Controls { base.OnPreRender(e); + //always reset the control vals + ResetPasswordCheckBox.Checked = false; + umbPasswordChanger_passwordCurrent.Text = null; + umbPasswordChanger_passwordNew.Text = null; + umbPasswordChanger_passwordNewConfirm.Text = null; + this.DataBind(); } diff --git a/src/Umbraco.Web.UI/umbraco/controls/PasswordChanger.ascx.designer.cs b/src/Umbraco.Web.UI/umbraco/controls/PasswordChanger.ascx.designer.cs index b56d057c6c..b5368261ac 100644 --- a/src/Umbraco.Web.UI/umbraco/controls/PasswordChanger.ascx.designer.cs +++ b/src/Umbraco.Web.UI/umbraco/controls/PasswordChanger.ascx.designer.cs @@ -12,8 +12,6 @@ namespace Umbraco.Web.UI.Umbraco.Controls { public partial class PasswordChanger { - - /// /// ResetPlaceHolder control. /// diff --git a/src/Umbraco.Web.UI/umbraco/controls/passwordChanger.ascx b/src/Umbraco.Web.UI/umbraco/controls/passwordChanger.ascx index dd00fddb61..065333995e 100644 --- a/src/Umbraco.Web.UI/umbraco/controls/passwordChanger.ascx +++ b/src/Umbraco.Web.UI/umbraco/controls/passwordChanger.ascx @@ -10,7 +10,7 @@ this.togglePasswordInputValidators(true); $(e).closest(".propertyItem").replaceWith($("#umbPasswordChanger")); $("#umbPasswordChanger").show(); - $("#<%=IsChangingPasswordField.ClientID%>").val(true); + $("#<%=IsChangingPasswordField.ClientID%>").val("true"); $(e).hide(); } }, @@ -20,11 +20,17 @@ ValidatorEnable(document.getElementById('<%=ConfirmPasswordValidator.ClientID %>'), true); ValidatorEnable(document.getElementById('<%=NewPasswordLengthValidator.ClientID %>'), true); if (!enablePassRetrieval) { - ValidatorEnable(document.getElementById('<%=CurrentPasswordValidator.ClientID %>'), true); + var currPassVal = document.getElementById('<%=CurrentPasswordValidator.ClientID %>'); + if (currPassVal) { + ValidatorEnable(currPassVal, true); + } } } else { - ValidatorEnable(document.getElementById('<%=CurrentPasswordValidator.ClientID %>'), false); + var currPassVal = document.getElementById('<%=CurrentPasswordValidator.ClientID %>'); + if (currPassVal) { + ValidatorEnable(currPassVal, false); + } ValidatorEnable(document.getElementById('<%=ConfirmPasswordValidator.ClientID %>'), false); ValidatorEnable(document.getElementById('<%=NewPasswordRequiredValidator.ClientID %>'), false); ValidatorEnable(document.getElementById('<%=NewPasswordLengthValidator.ClientID %>'), false); @@ -57,9 +63,9 @@ Change password
- -