From 2ec367fd5981a704e8ee8bf0f913ebae124a1cfb Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Wed, 4 Sep 2013 15:44:29 +0200 Subject: [PATCH] Removing the SecurityHelper and moving the 3 methods into the Provider as private classes, as they aren't used anywhere else. The SecUtility will be removed along with the legacy MembershipProvider when cleanup is possible. --- .../Providers/MembersMembershipProvider.cs | 18 ++-- src/Umbraco.Web/Security/SecurityHelper.cs | 88 ------------------- src/Umbraco.Web/Umbraco.Web.csproj | 1 - 3 files changed, 9 insertions(+), 98 deletions(-) delete mode 100644 src/Umbraco.Web/Security/SecurityHelper.cs diff --git a/src/Umbraco.Web/Security/Providers/MembersMembershipProvider.cs b/src/Umbraco.Web/Security/Providers/MembersMembershipProvider.cs index b638dcdff5..f02cd8eaae 100644 --- a/src/Umbraco.Web/Security/Providers/MembersMembershipProvider.cs +++ b/src/Umbraco.Web/Security/Providers/MembersMembershipProvider.cs @@ -183,16 +183,16 @@ namespace Umbraco.Web.Security.Providers // Initialize base provider class base.Initialize(name, config); - _applicationName = string.IsNullOrEmpty(config["applicationName"]) ? SecurityHelper.GetDefaultAppName() : config["applicationName"]; + _applicationName = string.IsNullOrEmpty(config["applicationName"]) ? GetDefaultAppName() : config["applicationName"]; - _enablePasswordRetrieval = SecurityHelper.GetBooleanValue(config, "enablePasswordRetrieval", false); - _enablePasswordReset = SecurityHelper.GetBooleanValue(config, "enablePasswordReset", false); - _requiresQuestionAndAnswer = SecurityHelper.GetBooleanValue(config, "requiresQuestionAndAnswer", false); - _requiresUniqueEmail = SecurityHelper.GetBooleanValue(config, "requiresUniqueEmail", true); - _maxInvalidPasswordAttempts = SecurityHelper.GetIntValue(config, "maxInvalidPasswordAttempts", 5, false, 0); - _passwordAttemptWindow = SecurityHelper.GetIntValue(config, "passwordAttemptWindow", 10, false, 0); - _minRequiredPasswordLength = SecurityHelper.GetIntValue(config, "minRequiredPasswordLength", 7, true, 0x80); - _minRequiredNonAlphanumericCharacters = SecurityHelper.GetIntValue(config, "minRequiredNonalphanumericCharacters", 1, true, 0x80); + _enablePasswordRetrieval = GetBooleanValue(config, "enablePasswordRetrieval", false); + _enablePasswordReset = GetBooleanValue(config, "enablePasswordReset", false); + _requiresQuestionAndAnswer = GetBooleanValue(config, "requiresQuestionAndAnswer", false); + _requiresUniqueEmail = GetBooleanValue(config, "requiresUniqueEmail", true); + _maxInvalidPasswordAttempts = GetIntValue(config, "maxInvalidPasswordAttempts", 5, false, 0); + _passwordAttemptWindow = GetIntValue(config, "passwordAttemptWindow", 10, false, 0); + _minRequiredPasswordLength = GetIntValue(config, "minRequiredPasswordLength", 7, true, 0x80); + _minRequiredNonAlphanumericCharacters = GetIntValue(config, "minRequiredNonalphanumericCharacters", 1, true, 0x80); _passwordStrengthRegularExpression = config["passwordStrengthRegularExpression"]; // make sure password format is Hashed by default. diff --git a/src/Umbraco.Web/Security/SecurityHelper.cs b/src/Umbraco.Web/Security/SecurityHelper.cs deleted file mode 100644 index ca22aa9901..0000000000 --- a/src/Umbraco.Web/Security/SecurityHelper.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System.Collections.Specialized; -using System.Configuration.Provider; -using System.Web.Hosting; - -namespace Umbraco.Web.Security -{ - internal class SecurityHelper - { - /// - /// Gets the boolean value. - /// - /// The config. - /// Name of the value. - /// if set to true [default value]. - /// - internal static bool GetBooleanValue(NameValueCollection config, string valueName, bool defaultValue) - { - bool flag; - var str = config[valueName]; - if (str == null) - return defaultValue; - - if (bool.TryParse(str, out flag) == false) - { - throw new ProviderException("Value must be boolean."); - } - return flag; - } - - /// - /// Gets the int value. - /// - /// The config. - /// Name of the value. - /// The default value. - /// if set to true [zero allowed]. - /// The max value allowed. - /// - internal static int GetIntValue(NameValueCollection config, string valueName, int defaultValue, bool zeroAllowed, int maxValueAllowed) - { - int num; - var s = config[valueName]; - if (s == null) - { - return defaultValue; - } - if (int.TryParse(s, out num) == false) - { - if (zeroAllowed) - { - throw new ProviderException("Value must be non negative integer"); - } - throw new ProviderException("Value must be positive integer"); - } - if (zeroAllowed && (num < 0)) - { - throw new ProviderException("Value must be non negativeinteger"); - } - if (zeroAllowed == false && (num <= 0)) - { - throw new ProviderException("Value must be positive integer"); - } - if ((maxValueAllowed > 0) && (num > maxValueAllowed)) - { - throw new ProviderException("Value too big"); - } - return num; - } - - - /// - /// Gets the name of the default app. - /// - /// - internal static string GetDefaultAppName() - { - try - { - var applicationVirtualPath = HostingEnvironment.ApplicationVirtualPath; - return string.IsNullOrEmpty(applicationVirtualPath) ? "/" : applicationVirtualPath; - } - catch - { - return "/"; - } - } - } -} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index a87f2fa449..ed3c6a1822 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -294,7 +294,6 @@ -