MembershipCreateStatus.InvalidPassword 如果我传递简单的单词

发布于 2024-10-25 11:40:12 字数 904 浏览 4 评论 0原文

我总是得到结果invalidpassword。我总是为所有用户传递Password="mypassword"。它是默认的

Membership.CreateUser(Constitid, Password, Email, question, Status, true, out result);

在 web.config 文件中:

<add name="AspNetSqlMembershipProvider" 
     type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
     connectionStringName="LocalSqlServer"
     enablePasswordRetrieval="false" 
     enablePasswordReset="true"
     requiresQuestionAndAnswer="true" 
     applicationName="/"
     requiresUniqueEmail="false"
     passwordFormat="Hashed" 
     maxInvalidPasswordAttempts="5"
     minRequiredPasswordLength="7" 
     minRequiredNonalphanumericCharacters="0" 
     passwordAttemptWindow="10"
     passwordStrengthRegularExpression="" />

传递简单密码不起作用?怎么解决这个问题?

I am getting results always invalidpassword. I am always passing for all users Password="mypassword". It is default

Membership.CreateUser(Constitid, Password, Email, question, Status, true, out result);

In web.config file:

<add name="AspNetSqlMembershipProvider" 
     type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
     connectionStringName="LocalSqlServer"
     enablePasswordRetrieval="false" 
     enablePasswordReset="true"
     requiresQuestionAndAnswer="true" 
     applicationName="/"
     requiresUniqueEmail="false"
     passwordFormat="Hashed" 
     maxInvalidPasswordAttempts="5"
     minRequiredPasswordLength="7" 
     minRequiredNonalphanumericCharacters="0" 
     passwordAttemptWindow="10"
     passwordStrengthRegularExpression="" />

Passing simple password will not work? how to solve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

止于盛夏 2024-11-01 11:40:12

反汇编 SqlMembershipProvider 后,它在以下情况下抛出 InvalidPassword - 标记为 **

我的猜测 - 检查您是否覆盖 MembershipProvider.ValidatingPassword 事件

  public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
    string str3;
    MembershipUser user;
    if (!SecUtility.ValidateParameter(ref password, true, true, false, 0x80))
    {
        status = **MembershipCreateStatus.InvalidPassword**;
        return null;
    }
    string salt = this.GenerateSalt();
    string objValue = this.EncodePassword(password, (int) this._PasswordFormat, salt);
    if (objValue.Length > 0x80)
    {
        status = **MembershipCreateStatus.InvalidPassword**;
        return null;
    }
    if (passwordAnswer != null)
    {
        passwordAnswer = passwordAnswer.Trim();
    }
    if (!string.IsNullOrEmpty(passwordAnswer))
    {
        if (passwordAnswer.Length > 0x80)
        {
            status = MembershipCreateStatus.InvalidAnswer;
            return null;
        }
        str3 = this.EncodePassword(passwordAnswer.ToLower(CultureInfo.InvariantCulture), (int) this._PasswordFormat, salt);
    }
    else
    {
        str3 = passwordAnswer;
    }
    if (!SecUtility.ValidateParameter(ref str3, this.RequiresQuestionAndAnswer, true, false, 0x80))
    {
        status = MembershipCreateStatus.InvalidAnswer;
        return null;
    }
    if (!SecUtility.ValidateParameter(ref username, true, true, true, 0x100))
    {
        status = MembershipCreateStatus.InvalidUserName;
        return null;
    }
    if (!SecUtility.ValidateParameter(ref email, this.RequiresUniqueEmail, this.RequiresUniqueEmail, false, 0x100))
    {
        status = MembershipCreateStatus.InvalidEmail;
        return null;
    }
    if (!SecUtility.ValidateParameter(ref passwordQuestion, this.RequiresQuestionAndAnswer, true, false, 0x100))
    {
        status = MembershipCreateStatus.InvalidQuestion;
        return null;
    }
    if ((providerUserKey != null) && !(providerUserKey is Guid))
    {
        status = MembershipCreateStatus.InvalidProviderUserKey;
        return null;
    }
    if (password.Length < this.MinRequiredPasswordLength)
    {
        status = **MembershipCreateStatus.InvalidPassword**;
        return null;
    }
    int num = 0;
    for (int i = 0; i < password.Length; i++)
    {
        if (!char.IsLetterOrDigit(password, i))
        {
            num++;
        }
    }
    if (num < this.MinRequiredNonAlphanumericCharacters)
    {
        status = **MembershipCreateStatus.InvalidPassword**;
        return null;
    }
    if ((this.PasswordStrengthRegularExpression.Length > 0) && !Regex.IsMatch(password, this.PasswordStrengthRegularExpression))
    {
        status = **MembershipCreateStatus.InvalidPassword**;
        return null;
    }
    ValidatePasswordEventArgs e = new ValidatePasswordEventArgs(username, password, true);
    this.OnValidatingPassword(e);
    if (e.Cancel)
    {
        status = **MembershipCreateStatus.InvalidPassword**;
        return null;
    }
    try
    {
        SqlConnectionHolder connection = null;
        try
        {
            connection = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true);
            this.CheckSchemaVersion(connection.Connection);
            DateTime time = this.RoundToSeconds(DateTime.UtcNow);
            SqlCommand command = new SqlCommand("dbo.aspnet_Membership_CreateUser", ....

            command.Parameters.Add(parameter);
            try
            {
                command.ExecuteNonQuery();
            }
            catch (SqlException exception)
            {
                if (((exception.Number != 0xa43) && (exception.Number != 0xa29)) && (exception.Number != 0x9d0))
                {
                    throw;
                }
                status = MembershipCreateStatus.DuplicateUserName;
                return null;
            }
            int num3 = (parameter.Value != null) ? ((int) parameter.Value) : -1;
            if ((num3 < 0) || (num3 > 11))
            {
                num3 = 11;
            }
            status = (MembershipCreateStatus) num3;
            if (num3 != 0)
            {
                return null;
            }
            providerUserKey = new Guid(command.Parameters["@UserId"].Value.ToString());
            time = time.ToLocalTime();
            user = new MembershipUser(this.Name, username, providerUserKey, email, passwordQuestion, null, isApproved, false, time, time, time, time, new DateTime(0x6da, 1, 1));
        }
        finally
        {
            if (connection != null)
            {
                connection.Close();
                connection = null;
            }
        }
    }
    catch
    {
        throw;
    }
    return user;
}


internal static bool ValidateParameter(ref string param, bool checkForNull, bool checkIfEmpty, bool checkForCommas, int maxSize)
{
    if (param == null)
    {
        return !checkForNull;
    }
    param = param.Trim();
    return (((!checkIfEmpty || (param.Length >= 1)) && ((maxSize <= 0) || (param.Length <= maxSize))) && (!checkForCommas || !param.Contains(",")));
}

After disassembling SqlMembershipProvider, it throws InvalidPassword in following cases - marked with **

my guess - check whether you override MembershipProvider.ValidatingPassword Event

  public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
    string str3;
    MembershipUser user;
    if (!SecUtility.ValidateParameter(ref password, true, true, false, 0x80))
    {
        status = **MembershipCreateStatus.InvalidPassword**;
        return null;
    }
    string salt = this.GenerateSalt();
    string objValue = this.EncodePassword(password, (int) this._PasswordFormat, salt);
    if (objValue.Length > 0x80)
    {
        status = **MembershipCreateStatus.InvalidPassword**;
        return null;
    }
    if (passwordAnswer != null)
    {
        passwordAnswer = passwordAnswer.Trim();
    }
    if (!string.IsNullOrEmpty(passwordAnswer))
    {
        if (passwordAnswer.Length > 0x80)
        {
            status = MembershipCreateStatus.InvalidAnswer;
            return null;
        }
        str3 = this.EncodePassword(passwordAnswer.ToLower(CultureInfo.InvariantCulture), (int) this._PasswordFormat, salt);
    }
    else
    {
        str3 = passwordAnswer;
    }
    if (!SecUtility.ValidateParameter(ref str3, this.RequiresQuestionAndAnswer, true, false, 0x80))
    {
        status = MembershipCreateStatus.InvalidAnswer;
        return null;
    }
    if (!SecUtility.ValidateParameter(ref username, true, true, true, 0x100))
    {
        status = MembershipCreateStatus.InvalidUserName;
        return null;
    }
    if (!SecUtility.ValidateParameter(ref email, this.RequiresUniqueEmail, this.RequiresUniqueEmail, false, 0x100))
    {
        status = MembershipCreateStatus.InvalidEmail;
        return null;
    }
    if (!SecUtility.ValidateParameter(ref passwordQuestion, this.RequiresQuestionAndAnswer, true, false, 0x100))
    {
        status = MembershipCreateStatus.InvalidQuestion;
        return null;
    }
    if ((providerUserKey != null) && !(providerUserKey is Guid))
    {
        status = MembershipCreateStatus.InvalidProviderUserKey;
        return null;
    }
    if (password.Length < this.MinRequiredPasswordLength)
    {
        status = **MembershipCreateStatus.InvalidPassword**;
        return null;
    }
    int num = 0;
    for (int i = 0; i < password.Length; i++)
    {
        if (!char.IsLetterOrDigit(password, i))
        {
            num++;
        }
    }
    if (num < this.MinRequiredNonAlphanumericCharacters)
    {
        status = **MembershipCreateStatus.InvalidPassword**;
        return null;
    }
    if ((this.PasswordStrengthRegularExpression.Length > 0) && !Regex.IsMatch(password, this.PasswordStrengthRegularExpression))
    {
        status = **MembershipCreateStatus.InvalidPassword**;
        return null;
    }
    ValidatePasswordEventArgs e = new ValidatePasswordEventArgs(username, password, true);
    this.OnValidatingPassword(e);
    if (e.Cancel)
    {
        status = **MembershipCreateStatus.InvalidPassword**;
        return null;
    }
    try
    {
        SqlConnectionHolder connection = null;
        try
        {
            connection = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true);
            this.CheckSchemaVersion(connection.Connection);
            DateTime time = this.RoundToSeconds(DateTime.UtcNow);
            SqlCommand command = new SqlCommand("dbo.aspnet_Membership_CreateUser", ....

            command.Parameters.Add(parameter);
            try
            {
                command.ExecuteNonQuery();
            }
            catch (SqlException exception)
            {
                if (((exception.Number != 0xa43) && (exception.Number != 0xa29)) && (exception.Number != 0x9d0))
                {
                    throw;
                }
                status = MembershipCreateStatus.DuplicateUserName;
                return null;
            }
            int num3 = (parameter.Value != null) ? ((int) parameter.Value) : -1;
            if ((num3 < 0) || (num3 > 11))
            {
                num3 = 11;
            }
            status = (MembershipCreateStatus) num3;
            if (num3 != 0)
            {
                return null;
            }
            providerUserKey = new Guid(command.Parameters["@UserId"].Value.ToString());
            time = time.ToLocalTime();
            user = new MembershipUser(this.Name, username, providerUserKey, email, passwordQuestion, null, isApproved, false, time, time, time, time, new DateTime(0x6da, 1, 1));
        }
        finally
        {
            if (connection != null)
            {
                connection.Close();
                connection = null;
            }
        }
    }
    catch
    {
        throw;
    }
    return user;
}


internal static bool ValidateParameter(ref string param, bool checkForNull, bool checkIfEmpty, bool checkForCommas, int maxSize)
{
    if (param == null)
    {
        return !checkForNull;
    }
    param = param.Trim();
    return (((!checkIfEmpty || (param.Length >= 1)) && ((maxSize <= 0) || (param.Length <= maxSize))) && (!checkForCommas || !param.Contains(",")));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文