Solved

Comparing two password fields in asp.net

Posted on 2003-11-06
2
391 Views
Last Modified: 2006-11-17

                                                Pasword<asp:textbox id="txtPassword" class="textarea" textmode="password" runat="server"/>
                                                <asp:requiredfieldvalidator id="validatePassword" runat="server" errormessage="<br/>Please Enter Password. " controltovalidate="txtPassword" display="dynamic"/>
                                                <asp:RegularExpressionValidator runat="server" ControlToValidate="txtPassword" ValidationExpression="[0-9a-zA-Z]{5,10}" ErrorMessage= "<br/>Login Id should be 5 to 10 characters or numbers." display="dynamic"/>

Repassword                                                <asp:textbox id="txtRePassword" class="textarea" textmode="password" runat="server"/>
                                                <asp:requiredfieldvalidator id="validaterePassword" runat="server" errormessage="<br/>Please Enter Re-Password. " controltovalidate="txtRePassword" display="dynamic"/>
                                                <asp:RegularExpressionValidator runat="server" ControlToValidate="txtRePassword" ValidationExpression="[0-9a-zA-Z]{5,10}" ErrorMessage= "<br/>Login Id should be 5 to 10 characters or numbers." display="dynamic"/>
                                                <asp:CompareValidator
                                                 ControlToValidate="txtPassword"
                                                 ControlToCompare="txtRePassword"
                                                 Display="Dynamic"
                                                 Text="<br/>Password and Re-Password does not match."
                                                 Runat="Server" />

I'm try to compare two password field from the above code.the code is working fine the only problem is that.
when the form loads it is obvious that both fields are blank.And when i type in the Password field and move to the next Re-password field that without me typing anything in Re-password field it already compares the value and gives me the Error msg (Password and Re-Password does not match.).

should it compare the values in the two textbox only after i've typed on both the text boxes or when i click the button.

thanks
0
Comment
Question by:swech
2 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 50 total points
ID: 9694227
you have the Validator set in REVERSE.  YOu want the validator to Validate txtRePassword against txtPassword, but you have it set backwards:

as you have it now coded:

asp:CompareValidator
                                         ControlToValidate="txtPassword"
                                         ControlToCompare="txtRePassword"
                                         Display="Dynamic"
                                         Text="<br/>Password and Re-Password does not match."
                                         Runat="Server" />

and it should be:

asp:CompareValidator
                                         ControlToValidate="txtRePassword"
                                         ControlToCompare="txtPassword"
                                         Display="Dynamic"
                                         Text="<br/>Password and Re-Password does not match."
                                         Runat="Server" />

that way the validation is not done until the txtRePassword TEXT is entered.

AW
0
 

Author Comment

by:swech
ID: 9694316
thanks for quick response.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now