public override void Initialize(string name, NameValueCollection config) { if (config == null) { throw new ArgumentNullException("config"); } if (String.IsNullOrEmpty(name)) { name = "AccessRoleProvider"; } if (string.IsNullOrEmpty(config["description"])) { config.Remove("description"); config.Add("description", "$safeprojectname$ Role Provider"); } base.Initialize(name, config); _DatabaseFileName = config["connectionStringName"]; if (_DatabaseFileName == null || _DatabaseFileName.Length < 1) { throw new ProviderException("Connection name not specified"); } string temp = MyConnectionHelper.GetFileNameFromConnectionName(_DatabaseFileName, true); if (temp == null || temp.Length < 1) { throw new ProviderException("Connection string not found: " + _DatabaseFileName); } _DatabaseFileName = temp; //HandlerBase.CheckAndReadRegistryValue(ref _DatabaseFileName, true); MyConnectionHelper.CheckConnectionString(_DatabaseFileName); _AppName = config["applicationName"]; if (string.IsNullOrEmpty(_AppName)) { _AppName = SecUtility.GetDefaultAppName(); } if (_AppName.Length > 255) { throw new ProviderException("Provider application name too long, max is 255."); } config.Remove("connectionStringName"); config.Remove("applicationName"); config.Remove("description"); if (config.Count > 0) { string attribUnrecognized = config.GetKey(0); if (!String.IsNullOrEmpty(attribUnrecognized)) { throw new ProviderException("Provider unrecognized attribute: " + attribUnrecognized); } } }
public override void Initialize(string name, NameValueCollection config) { if (config == null) { throw new ArgumentNullException("config"); } if (String.IsNullOrEmpty(name)) { name = "AccessMembershipProvider"; } if (string.IsNullOrEmpty(config["description"])) { config.Remove("description"); config.Add("description", "Membership $safeprojectname$ Provider"); } base.Initialize(name, config); _enablePasswordRetrieval = SecUtility.GetBooleanValue(config, "enablePasswordRetrieval", false); _enablePasswordReset = SecUtility.GetBooleanValue(config, "enablePasswordReset", true); _requiresQuestionAndAnswer = SecUtility.GetBooleanValue(config, "requiresQuestionAndAnswer", false); _requiresUniqueEmail = SecUtility.GetBooleanValue(config, "requiresUniqueEmail", false); _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); _hashAlgorithmType = config["hashAlgorithmType"]; if (String.IsNullOrEmpty(_hashAlgorithmType)) { _hashAlgorithmType = "MD5"; } _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; } _appName = config["applicationName"]; if (string.IsNullOrEmpty(_appName)) { _appName = SecUtility.GetDefaultAppName(); } if (_appName.Length > 255) { throw new ProviderException("Provider application name is too long, max length is 255."); } string strTemp = config["passwordFormat"]; if (strTemp == null) { strTemp = "Hashed"; } 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"); } if (_passwordFormat == MembershipPasswordFormat.Hashed && _enablePasswordRetrieval) { throw new ProviderException("Provider cannot retrieve hashed password"); } _databaseFileName = config["connectionStringName"]; if (_databaseFileName == null || _databaseFileName.Length < 1) { throw new ProviderException("Connection name not specified"); } string temp = MyConnectionHelper.GetFileNameFromConnectionName(_databaseFileName, true); if (temp == null || temp.Length < 1) { throw new ProviderException("Connection string not found: " + _databaseFileName); } _databaseFileName = temp; // Make sure connection is good MyConnectionHelper.CheckConnectionString(_databaseFileName); 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("passwordFormat"); config.Remove("name"); config.Remove("description"); config.Remove("minRequiredPasswordLength"); config.Remove("minRequiredNonalphanumericCharacters"); config.Remove("passwordStrengthRegularExpression"); config.Remove("hashAlgorithmType"); if (config.Count > 0) { string attribUnrecognized = config.GetKey(0); if (!String.IsNullOrEmpty(attribUnrecognized)) { throw new ProviderException("Provider unrecognized attribute: " + attribUnrecognized); } } }