我的教科书指出有效密码的默认值“要求您输入至少七个字符,其中一个字符为非字母数字。”我肯定是这样做的。我得到的错误是,“提供的密码答案无效。”这是aspx文件中的代码:
<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>
这是代码隐藏按钮单击事件:
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";
}
}
提前致谢!
答案 0 :(得分:0)
听起来你在安全配置中打开了问题和答案。查看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"