示例#1
0
        internal static void CheckArrayParameter(ref string[] param, bool checkForNull, bool checkIfEmpty, bool checkForCommas, int maxSize, string paramName)
        {
            if (param == null)
            {
                throw new ArgumentNullException(paramName);
            }

            if (param.Length < 1)
            {
                throw new ArgumentException(SM.GetString(SM.Parameter_array_empty, paramName), paramName);
            }

            Hashtable values = new Hashtable(param.Length);

            for (int i = param.Length - 1; i >= 0; i--)
            {
                SU.CheckParameter(ref param[i], checkForNull, checkIfEmpty, checkForCommas, maxSize,
                                  paramName + "[ " + i.ToString(CultureInfo.InvariantCulture) + " ]");
                if (values.Contains(param[i]))
                {
                    throw new ArgumentException(SM.GetString(SM.Parameter_duplicate_array_element, paramName), paramName);
                }
                else
                {
                    values.Add(param[i], param[i]);
                }
            }
        }
示例#2
0
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            SQLiteParameter[] parms =
            {
                SU.CreateInputParam("@ApplicationId",   DbType.String, ApplicationId),
                SU.CreateInputParam("@LoweredRoleName", DbType.String, roleName.ToLower())
            };
            int effect = 0;

            using (SQLiteConnection conn = SQLiteConnectionHelper.GetConnection(SqlConnectionString, true).Connection)
            {
                if (throwOnPopulatedRole)
                {
                    var obj = SQLiteHelper.ExecuteScalar(conn, CommandType.Text, Sql_IsExistUserInRole, parms);
                    if (obj != null)
                    {
                        throw new ProviderException(SM.GetString(SM.Role_is_not_empty));
                    }
                }
                effect = SQLiteHelper.ExecuteNonQuery(conn, CommandType.Text, Sql_Roles_Delete, parms);
                SQLiteHelper.ExecuteNonQuery(conn, CommandType.Text, Sql_DeleteUsersByRoleName, parms);
            }

            return(effect > 0);
        }
示例#3
0
        internal static void CheckParameter(ref string param, bool checkForNull, bool checkIfEmpty, bool checkForCommas, int maxSize, string paramName)
        {
            if (param == null)
            {
                if (checkForNull)
                {
                    throw new ArgumentNullException(paramName);
                }

                return;
            }

            param = param.Trim();
            if (checkIfEmpty && param.Length < 1)
            {
                throw new ArgumentException(SM.GetString(SM.Parameter_can_not_be_empty, paramName), paramName);
            }

            if (maxSize > 0 && param.Length > maxSize)
            {
                throw new ArgumentException(SM.GetString(SM.Parameter_too_long, paramName, maxSize.ToString(CultureInfo.InvariantCulture)), paramName);
            }

            if (checkForCommas && param.Contains(","))
            {
                throw new ArgumentException(SM.GetString(SM.Parameter_can_not_contain_comma, paramName), paramName);
            }
        }
示例#4
0
        internal static void GetPositiveAttribute(NameValueCollection config, string attrib, string providerName, ref int val)
        {
            string s = config.Get(attrib);
            int    t;

            if (s == null)
            {
                return;
            }

            try
            {
                t = Convert.ToInt32(s, CultureInfo.InvariantCulture);
            }
            catch (Exception e)
            {
                if (e is ArgumentException || e is FormatException || e is OverflowException)
                {
                    throw new ConfigurationErrorsException(
                              SM.GetString(SM.Invalid_provider_positive_attributes, attrib, providerName));
                }
                else
                {
                    throw;
                }
            }

            if (t < 0)
            {
                throw new ConfigurationErrorsException(
                          SM.GetString(SM.Invalid_provider_positive_attributes, attrib, providerName));
            }

            val = t;
        }
示例#5
0
        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 = "SQLiteRoleProvider";
            }
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", SM.GetString(SM.RoleSqlProvider_description));
            }
            base.Initialize(name, config);

            _schemaVersionCheck = 0;

            _commandTimeout = SU.GetIntValue(config, "commandTimeout", 30, true, 0);

            string temp = config["connectionStringName"];

            if (temp == null || temp.Length < 1)
            {
                throw new ProviderException(SM.GetString(SM.Connection_name_not_specified));
            }
            _sqlConnectionString = SQLiteConnectionHelper.GetConnectionString(temp, true, true);
            if (_sqlConnectionString == null || _sqlConnectionString.Length < 1)
            {
                throw new ProviderException(SM.GetString(SM.Connection_string_not_found, temp));
            }

            _applicationName = config["applicationName"];
            if (string.IsNullOrEmpty(_applicationName))
            {
                _applicationName = SU.GetDefaultAppName();
            }

            if (_applicationName.Length > 256)
            {
                throw new ProviderException(SM.GetString(SM.Provider_application_name_too_long));
            }

            config.Remove("connectionStringName");
            config.Remove("applicationName");
            config.Remove("commandTimeout");
            if (config.Count > 0)
            {
                string attribUnrecognized = config.GetKey(0);
                if (!String.IsNullOrEmpty(attribUnrecognized))
                {
                    throw new ProviderException(SM.GetString(SM.Provider_unrecognized_attribute, attribUnrecognized));
                }
            }
        }
示例#6
0
 internal static void CheckForUnrecognizedAttributes(XmlNode node)
 {
     if (node.Attributes.Count != 0)
     {
         throw new ConfigurationErrorsException(
                   SM.GetString(SM.Config_base_unrecognized_attribute, node.Attributes[0].Name),
                   node.Attributes[0]);
     }
 }
示例#7
0
 /// <summary>
 /// 创建一个数据库连接对象
 /// </summary>
 /// <param name="connectionString"></param>
 internal SQLiteConnectionHolder(string connectionString)
 {
     try
     {
         _Connection = new SQLiteConnection(connectionString);
     }
     catch (ArgumentException e)
     {
         throw new ArgumentException(SM.GetString(SM.SqlError_Connection_String), "connectionString", e);
     }
 }
示例#8
0
        internal static void CheckForbiddenAttribute(XmlNode node, string attrib)
        {
            XmlAttribute attr = node.Attributes[attrib];

            if (attr != null)
            {
                throw new ConfigurationErrorsException(
                          SM.GetString(SM.Config_base_unrecognized_attribute, attrib),
                          attr);
            }
        }
示例#9
0
 internal static void CheckUnrecognizedAttributes(NameValueCollection config, string providerName)
 {
     if (config.Count > 0)
     {
         string attribUnrecognized = config.GetKey(0);
         if (!String.IsNullOrEmpty(attribUnrecognized))
         {
             throw new ConfigurationErrorsException(
                       SM.GetString(SM.Unexpected_provider_attribute, attribUnrecognized, providerName));
         }
     }
 }
示例#10
0
 internal static void CheckForNonCommentChildNodes(XmlNode node)
 {
     foreach (XmlNode childNode in node.ChildNodes)
     {
         if (childNode.NodeType != XmlNodeType.Comment)
         {
             throw new ConfigurationErrorsException(
                       SM.GetString(SM.Config_base_no_child_nodes),
                       childNode);
         }
     }
 }
示例#11
0
        private static XmlNode GetAndRemoveNonEmptyStringAttributeInternal(XmlNode node, string attrib, bool fRequired, ref string val)
        {
            XmlNode a = GetAndRemoveStringAttributeInternal(node, attrib, fRequired, ref val);

            if (a != null && val.Length == 0)
            {
                throw new ConfigurationErrorsException(
                          SM.GetString(SM.Empty_attribute, attrib),
                          a);
            }

            return(a);
        }
示例#12
0
        private static XmlNode GetAndRemoveAttribute(XmlNode node, string attrib, bool fRequired)
        {
            XmlNode a = node.Attributes.RemoveNamedItem(attrib);

            // If the attribute is required and was not present, throw
            if (fRequired && a == null)
            {
                throw new ConfigurationErrorsException(
                          SM.GetString(SM.Missing_required_attribute, attrib, node.Name),
                          node);
            }

            return(a);
        }
示例#13
0
        // We don't trim the param before checking with password parameters
        internal static void CheckPasswordParameter(ref string param, int maxSize, string paramName)
        {
            if (param == null)
            {
                throw new ArgumentNullException(paramName);
            }

            if (param.Length < 1)
            {
                throw new ArgumentException(SM.GetString(SM.Parameter_can_not_be_empty, paramName), paramName);
            }

            if (maxSize > 0 && param.Length > maxSize)
            {
                throw new ArgumentException(SM.GetString(SM.Parameter_too_long, paramName, maxSize.ToString(CultureInfo.InvariantCulture)), paramName);
            }
        }
        internal string UnEncodePassword(string pass, int passwordFormat)
        {
            switch (passwordFormat)
            {
            case 0:     // MembershipPasswordFormat.Clear:
                return(pass);

            case 1:     // MembershipPasswordFormat.Hashed:
                throw new ProviderException(SM.GetString(SM.Provider_can_not_decode_hashed_password));

            default:
                byte[] bIn  = Convert.FromBase64String(pass);
                byte[] bRet = DecryptPassword(bIn);
                if (bRet == null)
                {
                    return(null);
                }
                return(Encoding.Unicode.GetString(bRet, 16, bRet.Length - 16));
            }
        }
示例#15
0
        internal static bool GetBooleanValue(NameValueCollection config, string valueName, bool defaultValue)
        {
            string sValue = config[valueName];

            if (sValue == null)
            {
                return(defaultValue);
            }

            bool result;

            if (bool.TryParse(sValue, out result))
            {
                return(result);
            }
            else
            {
                throw new ProviderException(SM.GetString(SM.Value_must_be_boolean, valueName));
            }
        }
示例#16
0
        internal static int GetIntValue(NameValueCollection config, string valueName, int defaultValue, bool zeroAllowed, int maxValueAllowed)
        {
            string sValue = config[valueName];

            if (sValue == null)
            {
                return(defaultValue);
            }

            int iValue;

            if (!Int32.TryParse(sValue, out iValue))
            {
                if (zeroAllowed)
                {
                    throw new ProviderException(SM.GetString(SM.Value_must_be_non_negative_integer, valueName));
                }

                throw new ProviderException(SM.GetString(SM.Value_must_be_positive_integer, valueName));
            }

            if (zeroAllowed && iValue < 0)
            {
                throw new ProviderException(SM.GetString(SM.Value_must_be_non_negative_integer, valueName));
            }

            if (!zeroAllowed && iValue <= 0)
            {
                throw new ProviderException(SM.GetString(SM.Value_must_be_positive_integer, valueName));
            }

            if (maxValueAllowed > 0 && iValue > maxValueAllowed)
            {
                throw new ProviderException(SM.GetString(SM.Value_too_big, valueName, maxValueAllowed.ToString(CultureInfo.InvariantCulture)));
            }

            return(iValue);
        }
示例#17
0
        // input.Xml cursor must be at a true/false XML attribute
        private static XmlNode GetAndRemoveBooleanAttributeInternal(XmlNode node, string attrib, bool fRequired, ref bool val)
        {
            XmlNode a = GetAndRemoveAttribute(node, attrib, fRequired);

            if (a != null)
            {
                if (a.Value == "true")
                {
                    val = true;
                }
                else if (a.Value == "false")
                {
                    val = false;
                }
                else
                {
                    throw new ConfigurationErrorsException(
                              SM.GetString(SM.Invalid_boolean_attribute, a.Name),
                              a);
                }
            }

            return(a);
        }
        public override void Initialize(string name, NameValueCollection config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (String.IsNullOrEmpty(name))
            {
                name = "SQLiteMembershipProvider";
            }
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", SM.GetString(SM.MembershipSqlProvider_description));
            }
            base.Initialize(name, config);

            _schemaVersionCheck = 0;

            _enablePasswordRetrieval              = SU.GetBooleanValue(config, "enablePasswordRetrieval", false);
            _enablePasswordReset                  = SU.GetBooleanValue(config, "enablePasswordReset", true);
            _requiresQuestionAndAnswer            = SU.GetBooleanValue(config, "requiresQuestionAndAnswer", true);
            _requiresUniqueEmail                  = SU.GetBooleanValue(config, "requiresUniqueEmail", true);
            _maxInvalidPasswordAttempts           = SU.GetIntValue(config, "maxInvalidPasswordAttempts", 5, false, 0);
            _passwordAttemptWindow                = SU.GetIntValue(config, "passwordAttemptWindow", 10, false, 0);
            _minRequiredPasswordLength            = SU.GetIntValue(config, "minRequiredPasswordLength", 7, false, 128);
            _minRequiredNonalphanumericCharacters = SU.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(SM.GetString(SM.MinRequiredNonalphanumericCharacters_can_not_be_more_than_MinRequiredPasswordLength));
            }

            _commandTimeout  = SU.GetIntValue(config, "commandTimeout", 30, true, 0);
            _ApplicationName = config["applicationName"];
            if (string.IsNullOrEmpty(_ApplicationName))
            {
                _ApplicationName = SU.GetDefaultAppName();
            }

            if (_ApplicationName.Length > 256)
            {
                throw new ProviderException(SM.GetString(SM.Provider_application_name_too_long));
            }

            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(SM.GetString(SM.Provider_bad_password_format));
            }

            if (PasswordFormat == MembershipPasswordFormat.Hashed && EnablePasswordRetrieval)
            {
                throw new ProviderException(SM.GetString(SM.Provider_can_not_retrieve_hashed_password));
            }
            //if (_PasswordFormat == MembershipPasswordFormat.Encrypted && MachineKeySection.IsDecryptionKeyAutogenerated)
            //    throw new ProviderException(SM.GetString(SM.Can_not_use_encrypted_passwords_with_autogen_keys));

            string temp = config["connectionStringName"];

            if (temp == null || temp.Length < 1)
            {
                throw new ProviderException(SM.GetString(SM.Connection_name_not_specified));
            }
            _sqlConnectionString = SQLiteConnectionHelper.GetConnectionString(temp, true, true);
            if (_sqlConnectionString == null || _sqlConnectionString.Length < 1)
            {
                throw new ProviderException(SM.GetString(SM.Connection_string_not_found, temp));
            }

            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(SM.GetString(SM.Provider_unrecognized_attribute, attribUnrecognized));
                }
            }
        }