0

How can i write query for Case sensitive in Linq to sql.

Present my query is:

   var userResults = from u in Adm.Registrations   
                     where u.UserName == userName && u.Password ==  passWord 
                     select u;

Thanks,

Sanjay
  • 1,570
  • 1
  • 13
  • 30
sampath kumar
  • 21
  • 1
  • 5

3 Answers3

4

NEVER, EVER store passwords in plain text in a database or anywhere else. NEVER. This is bad.

http://www.codinghorror.com/blog/2007/09/youre-probably-storing-passwords-incorrectly.html

My point here is not to drag the good names of the developers at Reddit through the mud. We're all guilty. I'm sure every developer reading this has stored passwords as plain text at some point in their career. I know I have. Forget the blame. The important thing is to teach our peers that storing plaintext passwords in the database is strictly forbidden-- that there's a better way, starting with basic hashes.

Use these references to help you in determining the best course of action. There are multiple ways to skin this cat. I realize that changing the way you store passwords is not a direct answer to your original question, and will involve more work on your part, but it will prevent more headaches down the line.

This is a very thorough guide to solving your plain text issue: http://www.codeproject.com/Articles/14537/The-Art-Science-of-Storing-Passwords

These links are also illuminating: Salting Your Password: Best Practices?

Non-random salt for password hashes

I hope this is more helpful that just the initial admonition.

Community
  • 1
  • 1
GrayFox374
  • 1,742
  • 9
  • 13
  • Right now this is not really an answer. You can easily turn it into one by mentioning e.g. how a hash would make things case sensitive. – ThiefMaster Jul 18 '12 at 07:11
2

If you haven't configured your database to perform case-sensitive comparison you will need to perform the comparison in memory, after getting the results from database.

var users = Adm.Registrations
               .Where(u => u.UserName == userName && u.Password == password)
               .ToList() // this will load data into memory
               // Now perform a case-sensitive query on the in-memory data
               .Where(u => u.UserName == userName && u.Password == password); 

Another option would be to change the collation of your database to perform case-sensitive search but be carefull as this may cause getting fewer results than expected in other queries or stored procedures.

RePierre
  • 9,358
  • 2
  • 20
  • 37
0

Try this

var userResults = from u in Adm.Registrations 
                      where u.UserName .Equals(userName,StringComparison.InvariantCultureIgnoreCase) && u.Password.Equals(passWord,InvariantCultureIgnoreCase)
                      select u;
Waqar Janjua
  • 6,113
  • 2
  • 26
  • 36