ASP.Net 会员资格提供程序:自定义创建用户

发布于 2024-11-29 00:24:45 字数 2133 浏览 1 评论 0原文

我的教科书指出,有效密码的默认设置“要求您输入至少七个字符,其中之一是非字母数字”。我肯定会这么做。我收到的错误是“提供的密码答案无效。”这是 aspx 文件中的代码:

<div id="loginBlock">
    First Name: <asp:TextBox ID="fname" runat="server"></asp:TextBox>&nbsp;&nbsp;
    Last Name: <asp:TextBox ID="lname" runat="server"></asp:TextBox><br />
    Username: <asp:TextBox ID="userName" runat="server"></asp:TextBox><br />
    Password: <asp:TextBox ID="passwd" runat="server" TextMode="Password"></asp:TextBox><br />
    Confirm Password: <asp:TextBox ID="passwdConfirm" runat="server" 
        TextMode="Password"></asp:TextBox>
    &nbsp;<asp:CompareValidator ID="validatePasswd"  CssClass="vaidator" ControlToValidate="passwdConfirm" ControlToCompare="passwd" runat="server" ErrorMessage="Passwords don't match! Re-enter."></asp:CompareValidator><br />
    Email:  <asp:TextBox ID="email" runat="server"></asp:TextBox><br />
    Confirm Email: <asp:TextBox ID="emailConfirm" runat="server"></asp:TextBox>
    &nbsp;<asp:CompareValidator ID="validateEmail"   CssClass="vaidator" ControlToValidate="emailConfirm" ControlToCompare="email" runat="server" ErrorMessage="Passwords don't match! Re-enter."></asp:CompareValidator><br />
    <asp:Button ID="submit" runat="server" Text="JOIN" onclick="submit_Click" /><br /><br />
    <asp:TextBox ID="loginError" CssClass="vaidator" runat="server" Width="300px" ReadOnly="True" 
        BorderStyle="None" Font-Size="0.9em" Rows="2"></asp:TextBox>
</div>

这是按钮单击事件的隐藏代码:

 protected void submit_Click(object sender, EventArgs e)
        {
            try
            {
                Membership.CreateUser(userName.Text, passwdConfirm.Text, email.Text);
            }
            catch (MembershipCreateUserException)
            {
                loginError.Text = "Password must be a minumum of 7 characters and contain at least one non-alphanumeric character";
            }
        }

提前致谢!

My textbook states that the default for a valid password, "requires that you enter at least seven characters with one of them being a non-alphanumeric." I am definitely doing that. The error I'm getting is, "The password answer supplied is invalid." Here is the code in the aspx file:

<div id="loginBlock">
    First Name: <asp:TextBox ID="fname" runat="server"></asp:TextBox>  
    Last Name: <asp:TextBox ID="lname" runat="server"></asp:TextBox><br />
    Username: <asp:TextBox ID="userName" runat="server"></asp:TextBox><br />
    Password: <asp:TextBox ID="passwd" runat="server" TextMode="Password"></asp:TextBox><br />
    Confirm Password: <asp:TextBox ID="passwdConfirm" runat="server" 
        TextMode="Password"></asp:TextBox>
     <asp:CompareValidator ID="validatePasswd"  CssClass="vaidator" ControlToValidate="passwdConfirm" ControlToCompare="passwd" runat="server" ErrorMessage="Passwords don't match! Re-enter."></asp:CompareValidator><br />
    Email:  <asp:TextBox ID="email" runat="server"></asp:TextBox><br />
    Confirm Email: <asp:TextBox ID="emailConfirm" runat="server"></asp:TextBox>
     <asp:CompareValidator ID="validateEmail"   CssClass="vaidator" ControlToValidate="emailConfirm" ControlToCompare="email" runat="server" ErrorMessage="Passwords don't match! Re-enter."></asp:CompareValidator><br />
    <asp:Button ID="submit" runat="server" Text="JOIN" onclick="submit_Click" /><br /><br />
    <asp:TextBox ID="loginError" CssClass="vaidator" runat="server" Width="300px" ReadOnly="True" 
        BorderStyle="None" Font-Size="0.9em" Rows="2"></asp:TextBox>
</div>

And here is the code-behind button-click event:

 protected void submit_Click(object sender, EventArgs e)
        {
            try
            {
                Membership.CreateUser(userName.Text, passwdConfirm.Text, email.Text);
            }
            catch (MembershipCreateUserException)
            {
                loginError.Text = "Password must be a minumum of 7 characters and contain at least one non-alphanumeric character";
            }
        }

Thanks in advance!

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

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

发布评论

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

评论(1

寄风 2024-12-06 00:24:45

听起来您已经在安全配置中打开了问答功能。检查您的 web.config 文件中的成员资格提供商部分,并检查 requiresQuestionAndAnswer="false"

在您的 web.config 文件中,您应该有一个定义成员资格提供程序设置的部分,如下所示:

<membership>
  <providers>
    <clear/>
      <add name="AspNetSqlMembershipProvider" passwordStrengthRegularExpression="^.*(?=^[^\s]{8,32}$)(?=.*[a-zA-Z])(?=.*[\d]).*$" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ConnSTR" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="20" minRequiredPasswordLength="8" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/myApp"/>
  </providers>
</membership>

您需要设置的位是:

requiresUniqueEmail="false"

Sounds like you've got question and answer turned on in the security configuration. Check your web.config file for the membership provider section and check that requiresQuestionAndAnswer="false".

In your web.config file you should have a section defining the membership provider settings, something like this:

<membership>
  <providers>
    <clear/>
      <add name="AspNetSqlMembershipProvider" passwordStrengthRegularExpression="^.*(?=^[^\s]{8,32}$)(?=.*[a-zA-Z])(?=.*[\d]).*$" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ConnSTR" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="20" minRequiredPasswordLength="8" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/myApp"/>
  </providers>
</membership>

The bit you need to set is:

requiresUniqueEmail="false"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文