Reputation: 167
I am using change password wizard to change the password. Is there any method to check whether the entered password and new password are same and if they are same then display an error message? I tried using code but it gives error message and also gives a success message saying that the password has been changed. Is it possible to put some compare validator to check these values?
Upvotes: 1
Views: 2576
Reputation: 1
You should have two text boxes, let's say txtNewPassword
and txtRePass
. This will do the job, and as seen below the built in <asp:CompareValidator>
will do the job.
But if you also want an extra validation you can also add Validation Group = ""
<asp:CompareValidator runat="server" ID="Comp1" ControlToValidate="txtNewPassword" ControlToCompare="txtRePass" Text="Password mismatch" Font-Size="11px" ForeColor="Red"/>`
Upvotes: 0
Reputation: 31
Try
asp:CompareValidator
with Operator "property = NotEqual"
this should work
Upvotes: 0
Reputation: 167
I got the solution. Instead of using change password template, i used the code
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;
}
Initially lable1 was enter different current and new passwords.
Upvotes: 0
Reputation: 485
Add one more validator on the your change password webpage. try the following validator:
<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>
Upvotes: 2
Reputation: 14460
If you creating your own control,
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
Upvotes: 0