Click here to Skip to main content
16,019,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day please i created a login form but i noticed that the username and password is not case sensitive when the password is in capital letter the user can use small letter to log in which is not proper.

What I have tried:

 SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "Select * from Registration where Uname=@user and Password=@pass collate Latin1_General_CS_AS";
            cmd.Parameters.AddWithValue("@user", txtuser.Text);
            cmd.Parameters.AddWithValue("@pass", txtpass.Text);
//          
Posted
Updated 19-Oct-17 3:25am
Comments
PIEBALDconsult 18-Oct-17 19:10pm    
Never store passwords like that.

https://www.codeproject.com/Tips/186585/Password-Storage-How-to-do-it
https://www.codeproject.com/Articles/704865/Salted-Password-Hashing-Doing-it-Right
https://www.codeproject.com/Articles/608860/Understanding-and-Implementing-Password-Hashing
https://www.codeproject.com/Articles/14537/The-Art-Science-of-Storing-Passwords
Maciej Los 19-Oct-17 2:01am    
My virtual 5!
Patrice T 19-Oct-17 8:32am    
What makes you think that the database is not case sensitive ?
Richard Deeming 20-Oct-17 11:52am    
Passwords should be case sensitive. Storing them properly, as mentioned above, will take care of that.

Usernames should not be case sensitive. Why would you want john, John and JOhn to be three separate users? Not to mention the additional burden on the users of making them remember the precise case of their username.

1 solution

If you do have to have passwords this way then change your COLLATE statement to be SQL_Latin1_General_CP1_CS_AS. That will make the password case sensitive.
 
Share this answer
 
Comments
akinwunmi 19-Oct-17 18:55pm    
it is given me incorrect syntax near SQL_Latin1_General_CP1_CS_AS
ZurdoDev 19-Oct-17 19:50pm    
Then you'll need to fix the syntax. Not sure what you want me to tell you. You typed something in wrong.
akinwunmi 22-Oct-17 3:17am    
this is the code
cmd.CommandText = "Select * from Registration where Uname=@user and Password=@pass SQL_Latin1_General_CP1_CS_AS";
ZurdoDev 22-Oct-17 10:21am    
You need the word COLLATE.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900