public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config) { if (config == null) { throw new ArgumentNullException("config"); } if (string.IsNullOrEmpty(name)) { name = "FRACMembershipProvider"; } if (string.IsNullOrEmpty(config["description"])) { config.Remove("description"); config.Add("description", "FRAC Membership Provider"); } //Initialize the base class base.Initialize(name, config); // Initialize default values _ApplicationName = "DefaultApp"; _ConnectionString = @"Data Source=ROBERTO;Initial Catalog=Kong;Integrated Security=True"; _Description = "DefaultApp"; _MinRequiredPasswordLength = SecUtility.GetIntValue(config, "minRequiredPasswordLength", 7, false, 128); _MinRequiredNonalphanumericCharacters = SecUtility.GetIntValue(config, "minRequiredNonalphanumericCharacters", 1, true, 128); _EnablePasswordRetrieval = SecUtility.GetBooleanValue(config, "enablePasswordRetrieval", false); _EnablePasswordReset = SecUtility.GetBooleanValue(config, "enablePasswordReset", true); _Name = name; // Now go through the properties and initialize custom values foreach (string key in config.Keys) { switch (key.ToLower()) { case "applicationname": _ApplicationName = config[key]; break; case "connectionstring": _ConnectionString = config[key]; break; case "description": _Description = config[key]; break; case "requiresquestionandanswer": _RequiresQuestionAndAnswer = SecUtility.GetBooleanValue(config, key, true); break; case "requiresuniqueemail": _RequiresUniqueEmail = SecUtility.GetBooleanValue(config, key, true); break; } } string strTemp = string.IsNullOrEmpty(config["passwordFormat"]) ? "Hashed" : config["passwordFormat"]; switch (strTemp) { case "Clear": _PasswordFormat = MembershipPasswordFormat.Clear; break; case "Encrypted": _PasswordFormat = MembershipPasswordFormat.Encrypted; break; case "Hashed": _PasswordFormat = MembershipPasswordFormat.Hashed; break; default: throw new ProviderException("Bad password format"); } _HashAlgorithmType = config["hashAlgorithmType"]; if (String.IsNullOrEmpty(_HashAlgorithmType)) { _HashAlgorithmType = "SHA1"; } if (_PasswordStrengthRegularExpression != null) { _PasswordStrengthRegularExpression = _PasswordStrengthRegularExpression.Trim(); if (_PasswordStrengthRegularExpression.Length != 0) { try { Regex regex = new Regex(_PasswordStrengthRegularExpression); } catch (ArgumentException e) { throw new ProviderException(e.Message, e); } } } else { _PasswordStrengthRegularExpression = string.Empty; } if (_PasswordFormat == MembershipPasswordFormat.Hashed && _EnablePasswordRetrieval) { throw new ProviderException("Provider cannot retrieve hashed password"); } //Setup the dataops -- We probably want to change the 'connection string' to a connection string key //pointing to a web.config connection strings section _dops = new DataOps(); _dops.ConnectionString = _ConnectionString; }
/// <summary> /// Initializes the provider. /// </summary> /// <param name="name">The friendly name of the provider.</param> /// <param name="config">A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.</param> /// <exception cref="T:System.ArgumentNullException">The name of the provider is null.</exception> /// <exception cref="T:System.InvalidOperationException">An attempt is made to call /// <see cref="M:System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection)"></see> on a provider after the provider /// has already been initialized.</exception> /// <exception cref="T:System.ArgumentException">The name of the provider has a length of zero.</exception> public override void Initialize(string name, NameValueCollection config) { // Intialize values from web.config if (config == null) { throw new ArgumentNullException("config"); } if (string.IsNullOrEmpty(name)) { name = "UmbracoMembershipProvider"; } // Initialize base provider class base.Initialize(name, config); m_providerName = name; this.m_EnablePasswordRetrieval = SecUtility.GetBooleanValue(config, "enablePasswordRetrieval", false); this.m_EnablePasswordReset = SecUtility.GetBooleanValue(config, "enablePasswordReset", false); this.m_RequiresQuestionAndAnswer = SecUtility.GetBooleanValue(config, "requiresQuestionAndAnswer", false); this.m_RequiresUniqueEmail = SecUtility.GetBooleanValue(config, "requiresUniqueEmail", true); this.m_MaxInvalidPasswordAttempts = SecUtility.GetIntValue(config, "maxInvalidPasswordAttempts", 5, false, 0); this.m_PasswordAttemptWindow = SecUtility.GetIntValue(config, "passwordAttemptWindow", 10, false, 0); this.m_MinRequiredPasswordLength = SecUtility.GetIntValue(config, "minRequiredPasswordLength", 7, true, 0x80); this.m_MinRequiredNonAlphanumericCharacters = SecUtility.GetIntValue(config, "minRequiredNonalphanumericCharacters", 1, true, 0x80); this.m_PasswordStrengthRegularExpression = config["passwordStrengthRegularExpression"]; this.m_ApplicationName = config["applicationName"]; if (string.IsNullOrEmpty(this.m_ApplicationName)) { this.m_ApplicationName = SecUtility.GetDefaultAppName(); } // make sure password format is clear by default. string str = config["passwordFormat"]; if (str == null) { str = "Clear"; } switch (str.ToLower()) { case "clear": this.m_PasswordFormat = MembershipPasswordFormat.Clear; break; case "encrypted": this.m_PasswordFormat = MembershipPasswordFormat.Encrypted; break; case "hashed": this.m_PasswordFormat = MembershipPasswordFormat.Hashed; break; default: throw new ProviderException("Provider bad password format"); } if ((this.PasswordFormat == MembershipPasswordFormat.Hashed) && this.EnablePasswordRetrieval) { throw new ProviderException("Provider can not retrieve hashed password"); } // test for membertype (if not specified, choose the first member type available) if (config["defaultMemberTypeAlias"] != null) { m_DefaultMemberTypeAlias = config["defaultMemberTypeAlias"]; } else if (MemberType.GetAll.Length == 1) { m_DefaultMemberTypeAlias = MemberType.GetAll[0].Alias; } else { throw new ProviderException("No default MemberType alias is specified in the web.config string. Please add a 'defaultMemberTypeAlias' to the add element in the provider declaration in web.config"); } // test for approve status if (config["umbracoApprovePropertyTypeAlias"] != null) { m_ApprovedPropertyTypeAlias = config["umbracoApprovePropertyTypeAlias"]; } // test for lock attempts if (config["umbracoLockPropertyTypeAlias"] != null) { m_LockPropertyTypeAlias = config["umbracoLockPropertyTypeAlias"]; } if (config["umbracoFailedPasswordAttemptsPropertyTypeAlias"] != null) { m_FailedPasswordAttemptsPropertyTypeAlias = config["umbracoFailedPasswordAttemptsPropertyTypeAlias"]; } // comment property if (config["umbracoCommentPropertyTypeAlias"] != null) { m_CommentPropertyTypeAlias = config["umbracoCommentPropertyTypeAlias"]; } // last login date if (config["umbracoLastLoginPropertyTypeAlias"] != null) { m_LastLoginPropertyTypeAlias = config["umbracoLastLoginPropertyTypeAlias"]; } // password retrieval if (config["umbracoPasswordRetrievalQuestionPropertyTypeAlias"] != null) { m_PasswordRetrievalQuestionPropertyTypeAlias = config["umbracoPasswordRetrievalQuestionPropertyTypeAlias"]; } if (config["umbracoPasswordRetrievalAnswerPropertyTypeAlias"] != null) { m_PasswordRetrievalAnswerPropertyTypeAlias = config["umbracoPasswordRetrievalAnswerPropertyTypeAlias"]; } }
public override void Initialize(string name, NameValueCollection config) { // Remove CAS from sample: HttpRuntime.CheckAspNetHostingPermission (AspNetHostingPermissionLevel.Low, SR.Feature_not_supported_at_this_level); if (config == null) { throw new ArgumentNullException("config"); } if (String.IsNullOrEmpty(name)) { name = "MyMembershipProvider"; } if (string.IsNullOrEmpty(config["description"])) { config.Remove("description"); config.Add("description", SR.GetString(SR.MembershipSqlProvider_description)); } base.Initialize(name, config); _EnablePasswordRetrieval = SecUtility.GetBooleanValue(config, "enablePasswordRetrieval", false); _EnablePasswordReset = SecUtility.GetBooleanValue(config, "enablePasswordReset", true); _RequiresQuestionAndAnswer = SecUtility.GetBooleanValue(config, "requiresQuestionAndAnswer", true); _RequiresUniqueEmail = SecUtility.GetBooleanValue(config, "requiresUniqueEmail", true); _MaxInvalidPasswordAttempts = SecUtility.GetIntValue(config, "maxInvalidPasswordAttempts", 5, false, 0); _PasswordAttemptWindow = SecUtility.GetIntValue(config, "passwordAttemptWindow", 10, false, 0); _MinRequiredPasswordLength = SecUtility.GetIntValue(config, "minRequiredPasswordLength", 7, false, 128); _MinRequiredNonalphanumericCharacters = SecUtility.GetIntValue(config, "minRequiredNonalphanumericCharacters", 1, true, 128); _PasswordStrengthRegularExpression = config["passwordStrengthRegularExpression"]; if (_PasswordStrengthRegularExpression != null) { _PasswordStrengthRegularExpression = _PasswordStrengthRegularExpression.Trim(); if (_PasswordStrengthRegularExpression.Length != 0) { try { Regex regex = new Regex(_PasswordStrengthRegularExpression); } catch (ArgumentException e) { throw new ProviderException(e.Message, e); } } } else { _PasswordStrengthRegularExpression = string.Empty; } if (_MinRequiredNonalphanumericCharacters > _MinRequiredPasswordLength) { throw new HttpException(SR.GetString(SR.MinRequiredNonalphanumericCharacters_can_not_be_more_than_MinRequiredPasswordLength)); } config.Remove("connectionStringName"); config.Remove("enablePasswordRetrieval"); config.Remove("enablePasswordReset"); config.Remove("requiresQuestionAndAnswer"); config.Remove("applicationName"); config.Remove("requiresUniqueEmail"); config.Remove("maxInvalidPasswordAttempts"); config.Remove("passwordAttemptWindow"); config.Remove("commandTimeout"); config.Remove("passwordFormat"); config.Remove("name"); config.Remove("minRequiredPasswordLength"); config.Remove("minRequiredNonalphanumericCharacters"); config.Remove("passwordStrengthRegularExpression"); if (config.Count > 0) { string attribUnrecognized = config.GetKey(0); if (!String.IsNullOrEmpty(attribUnrecognized)) { throw new ProviderException(SR.GetString(SR.Provider_unrecognized_attribute, attribUnrecognized)); } } }