2011-08-10 145 views
0

我的教科書指出,一個有效的密碼默認情況下,「要求你輸入至少七個字符其中一人是一個非字母數字。」我絕對是這麼做的。我收到的錯誤是,「提供的密碼答案是無效的。」提前ASP.Net成員資格提供:自定義創建用戶

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

感謝:這裏是在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> 

這裏是代碼隱藏按鈕單擊事件!

+0

什麼是你的會員的配置樣子在你的web.config? –

回答

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" 
+0

Susan

+0

這些是我的web.config中的值 - 我需要添加該聲明? – Susan

+0

不可以。您正在尋找位於 .... –

相關問題