更改密码控制验证



我正在使用更改密码向导更改密码。有没有办法检查输入的密码和新密码是否相同,如果相同则显示错误信息?我尝试使用代码,但它给出了错误消息,也给出了一个成功的消息,说密码已更改。是否可以放置一些比较验证器来检查这些值?

在更改密码页面上添加一个验证器。尝试以下验证器:

<asp:CompareValidator ID="CompareValidator1"
     runat="server"
     ControlToCompare="NewPassword" // ID of your new password field
     ControlToValidate="CurrentPassword"  //ID of  current password field
     ErrorMessage="You should enter different password." 
     ForeColor="Red">
</asp:CompareValidator>

如果您创建自己的控件,

 1. check the current user who is logged in
 2. when user try to change the password, probably a button click
    get the users unique id and match the new password and old password.
 3. If password match return an error, update the database with new password otherwise

我找到解决办法了。我没有使用change password template,而是使用了代码

protected void ChangePassword1_ChangedPassword(object sender, EventArgs e)
    {
        if (ChangePassword1.CurrentPassword == ChangePassword1.NewPassword)
        {
            Response.Redirect("ChangePassword.aspx");
        }
        //Label1.Text = "current and new passwords should not match";        
        Label1.Visible = false;
    }

最初lable1输入不同的当前密码和新密码

Try

asp: CompareValidator

使用Operator "property = NotEqual"

应该可以

你应该有两个文本框,假设是txtNewPasswordtxtRePass。这将做的工作,并如下所示,内置在<asp:CompareValidator>将做的工作。但是如果你还想要一个额外的验证,你也可以添加Validation Group = ""

<asp:CompareValidator runat="server" ID="Comp1" ControlToValidate="txtNewPassword" ControlToCompare="txtRePass" Text="Password mismatch" Font-Size="11px" ForeColor="Red"/>`

最新更新