password should not be username

Posted by Srinunelli under ASP.NET on 2/5/2012 | Points: 10 | Views : 1753 | Status : [Member] | Replies : 10
hi... i want any validations for password is not same as username......




Responses

Posted by: MF-13693 on: 2/5/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

Use this function to validate that the password should not be username.

Public Function PassLikUsername(ByVal uName as String, ByVal pWord as String) as Boolean

Dim retVal as Boolean = False

If uName = pWord then
retVal = True
End If
Return retVal
End Function


Usage:

If PassLikUsername(strUsername, strPass) then
Msgbox("Cannot use password as username !!")
End if



Hope this Helps.

M@F
Index was outside the bounds !!!

Srinunelli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 2/6/2012 [Member] Starter | Points: 25

Up
0
Down
HI,

Compare value of User name and Password like this
If (txtUserName.text == txtPasswrd.Text)

{
.. Show Message Box
}
else
{
// Do something................
}


Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Srinunelli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 2/8/2012 [Member] Silver | Points: 25

Up
0
Down
Hi,
Why dont you use Compare Validator or javascript to check username and password in front end only.

Thanks,
Sanjay

Srinunelli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bipro.reader on: 2/15/2012 [Member] Starter | Points: 25

Up
0
Down
@Naraayanan:
if I enter
User Name: test
Password: Test
ur code will not catch the difference.
Solution:
Convert both the "User Name" and "Password" fields' text value into lower case or uppercase then compare.

Srinunelli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Websoftcreation on: 2/15/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

You can use comapare validator or compare textboxes value by C#
i.e
if(txt_UserName.Text==txt_Password.Text)
{
Response.Write("UserName and password can't be same);
}
else
{
Response.Write("Ok");
}

Regards

Websoftcreation,Jaipur

Websoftcreation
website: http://www.websoftcreation.co.in

Srinunelli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sukesh.net on: 2/15/2012 [Member] Starter | Points: 25

Up
0
Down
I think the best way is to use compare validator for both text boxes..

Thanks
Sukesh

Srinunelli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bipro.reader on: 2/15/2012 [Member] Starter | Points: 25

Up
0
Down
I think its easy to edit the Java Script at client side and bypass the validation.
again CompareValidator can't catch if the text case changed for e.g,
User Name: test ; Password: Test
Use the below code snippet on the button click event,
if (txtUSerName.Text.ToUpper() == txtPassword.Text.ToUpper())
lblError.Text = "ERROR:Username & Password can't be identical";
else
lblError.Text = "Logged in successfully";


Srinunelli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 2/15/2012 [Member] Silver | Points: 25

Up
0
Down
Guys!!!
Try This
<form id="form1" runat="server">

<div>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="UserName is Required"></asp:RequiredFieldValidator>
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox2" ErrorMessage="Please provide password"></asp:RequiredFieldValidator>
<br />
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TextBox1" ControlToValidate="TextBox2"
ErrorMessage="Username and password cannot be identical"></asp:CompareValidator>
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Login" />

</div>
</form>


Thanks,
Sanjay

Srinunelli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 2/15/2012 [Member] Silver | Points: 25

Up
0
Down
Try giving test and Test
It wont allow

Thanks,
Sanjay

Srinunelli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bipro.reader on: 2/15/2012 [Member] Starter | Points: 25

Up
0
Down
Enter "test" (same value) in both User Name and Password field, CompareValidator won't stop
CompareValidator is not the solution in this case.
We use CompareValidator to check Password and Repeat Password field.

Srinunelli, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response