Exemplo n.º 1
0
        /// <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, System.Collections.Specialized.NameValueCollection config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            SecurityUtil.EnsureDataFoler();
            /// prerequisite
            if (string.IsNullOrEmpty(name))
            {
                name = DefaultProviderName;
            }
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", DefaultProviderDescription);
            }

            // base initialize
            base.Initialize(name, config);

            // initialize fields
            _applicationName = SecurityUtil.GetConfigValue(config["applicationName"], System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
            string fileName = SecurityUtil.GetConfigValue(config["fileName"], DefaultFileName);

            _fileName = SecurityUtil.MapPath(string.Format("~/App_Data/{0}", fileName));
        }
Exemplo n.º 2
0
        /// <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)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            SecurityUtil.EnsureDataFoler();
            if (string.IsNullOrEmpty(name))
            {
                name = DefaultProviderName;
            }
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", DefaultProviderDescription);
            }

            // Initialize the abstract base class.
            base.Initialize(name, config);

            // initialize custom fields
            _applicationName = SecurityUtil.GetConfigValue(config["applicationName"],
                                                           System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
            string fileName = SecurityUtil.GetConfigValue(config["fileName"], DefaultFileName);
            string folder   = SecurityUtil.GetConfigValue(config["folder"], SecurityUtil.DefaultFolder);

            if (!folder.EndsWith("/"))
            {
                folder += "/";
            }
            _fileName = SecurityUtil.MapPath(string.Format("{0}{1}", folder, fileName));
        }
        /// <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)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            SecurityUtil.EnsureDataFoler();
            if (string.IsNullOrEmpty(name))
            {
                name = DefaultProviderName;
            }
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", DefaultProviderDescription);
            }

            // Initialize the abstract base class.
            base.Initialize(name, config);

            // initialize fields
            _enablePasswordReset = Convert.ToBoolean(
                SecurityUtil.GetConfigValue(config["enablePasswordReset"], bool.TrueString));
            _maxInvalidPasswordAttempts = Convert.ToInt32(
                SecurityUtil.GetConfigValue(config["maxInvalidPasswordAttempts"], "5"));
            _minRequiredNonAlphanumericCharacters = Convert.ToInt32(
                SecurityUtil.GetConfigValue(config["minRequiredNonAlphanumericCharacters"], "0"));
            _minRequiredPasswordLength = Convert.ToInt32(
                SecurityUtil.GetConfigValue(config["minRequiredPasswordLength"], "5"));
            _passwordAttemptWindow = Convert.ToInt32(
                SecurityUtil.GetConfigValue(config["passwordAttemptWindow"], "10"));
            // >> FIX: http://www.codeplex.com/aspnetxmlproviders/WorkItem/View.aspx?WorkItemId=6743
            _passwordFormat = (MembershipPasswordFormat)Enum.Parse(
                typeof(MembershipPasswordFormat), SecurityUtil.GetConfigValue(config["passwordFormat"], "2"));
            // << FIX
            _passwordStrengthRegularExpression = Convert.ToString(
                SecurityUtil.GetConfigValue(config["passwordStrengthRegularExpression"], @"[\w| !§$%&/()=\-?\*]*"));
            _requiresQuestionAndAnswer = Convert.ToBoolean(
                SecurityUtil.GetConfigValue(config["requiresQuestionAndAnswer"], bool.FalseString));
            _requiresUniqueEmail = Convert.ToBoolean(
                SecurityUtil.GetConfigValue(config["requiresUniqueEmail"], bool.TrueString));

            // initialize custom fields
            _applicationName = SecurityUtil.GetConfigValue(config["applicationName"],
                                                           System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
            // >> FIX: http://www.codeplex.com/aspnetxmlproviders/WorkItem/View.aspx?WorkItemId=9700
            string fileName = SecurityUtil.GetConfigValue(config["fileName"], DefaultFileName);

            _fileName = SecurityUtil.MapPath(string.Format("~/App_Data/{0}", fileName));
            // << FIX
            // starter User setup
            string initialRole     = config["initialRole"];
            string initialUser     = config["initialUser"];
            string initialPassword = config["initialPassword"];

            if (!string.IsNullOrEmpty(initialRole) &&
                !string.IsNullOrEmpty(initialUser) &&
                !string.IsNullOrEmpty(initialPassword))
            {
                //
                SetupInitialUser(initialRole, initialUser, initialPassword);
            }
        }