예제 #1
0
        public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
        {
            if (providerUserKey == null)
            {
                throw new ArgumentNullException("providerUserKey");
            }
            if (!(providerUserKey is Guid))
            {
                throw new ArgumentException(SM.GetString(SM.Membership_InvalidProviderUserKey), "providerUserKey");
            }
            var bll   = new SiteUsers();
            var model = bll.GetModelByJoin(null, providerUserKey);

            if (model == null)
            {
                return(null);
            }
            return(new MembershipUser(this.Name, model.Named, model.Id, model.Email, model.PasswordQuestion, model.Comment, model.IsApproved, model.IsLockedOut, model.CreateDate, model.LastLoginDate, model.LastActivityDate, model.LastPasswordChangedDate, model.LastLockoutDate));
        }
예제 #2
0
        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));
            }
        }
예제 #3
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));
            }
        }
예제 #4
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);
        }
예제 #5
0
        public override void Initialize(string name, NameValueCollection config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (String.IsNullOrEmpty(name))
            {
                name = "SqlMembershipProvider";
            }
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", SM.GetString(SM.MembershipSqlProvider_description));
            }
            base.Initialize(name, config);

            _SchemaVersionCheck = 0;

            _EnablePasswordRetrieval              = SC.GetBooleanValue(config, "enablePasswordRetrieval", false);
            _EnablePasswordReset                  = SC.GetBooleanValue(config, "enablePasswordReset", true);
            _RequiresQuestionAndAnswer            = SC.GetBooleanValue(config, "requiresQuestionAndAnswer", true);
            _RequiresUniqueEmail                  = SC.GetBooleanValue(config, "requiresUniqueEmail", true);
            _MaxInvalidPasswordAttempts           = SC.GetIntValue(config, "maxInvalidPasswordAttempts", 5, false, 0);
            _PasswordAttemptWindow                = SC.GetIntValue(config, "passwordAttemptWindow", 10, false, 0);
            _MinRequiredPasswordLength            = SC.GetIntValue(config, "minRequiredPasswordLength", 7, false, 128);
            _MinRequiredNonalphanumericCharacters = SC.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 = SC.GetIntValue(config, "commandTimeout", 30, true, 0);
            _AppName        = config["applicationName"];
            if (string.IsNullOrEmpty(_AppName))
            {
                _AppName = SC.GetDefaultAppName();
            }

            if (_AppName.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(SecurityMessage.GetString(SecurityMessage.Can_not_use_encrypted_passwords_with_autogen_keys));

            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));
                }
            }
        }