views:

557

answers:

4

Hi All, In my application I am sending password to database,lets say my Password is PassworD123. Now this is giving me proper value ,but when i am using password123..its also giving me the proper value.So how to chaeck for case sensitive data in SQL server. Any demo code will help. Thanks.

+5  A: 

Why not use encryption to store the passwords in the database such as md5 because they will return different hashed versions for example

Md5 of password123 = 482c811da5d5b4bc6d497ffa98491e38

Md5 of PassworD123 = bbac8ba35cdef1b1e6c40f82ff8002ea

and when you compare them 2 they are clearly different.

I think you are using ASP therefore i dont know if it has an md5() function built in but php does have it. Another thing you should know is that if you are storing passwords in a database its better to store them using some sort of encryption that cannot be reversed

Shahmir Javaid
Thanks.Good Point.
Wondering
I strongly encourage you to read the link I posted in my response. "MD5" is no longer an acceptable answer.
TML
^ I agree, therefore i only suggest the above for an example just to get a clear pic :D
Shahmir Javaid
Sorry, that wasn't intended to come across as critical - merely a strong encouragment to Wondering to read up on the subject.
TML
I read it and i must say its a must read before building a database that needs password storage :D
Shahmir Javaid
+2  A: 

The immediate answer to your query is here: http://sqlserver2000.databases.aspfaq.com/how-can-i-make-my-sql-queries-case-sensitive.html

However I think your approach to storing / comparing passwords is a bit wrong. You should not be storing the password directly in the database. At-least MD5 it or something.

Alterlife
+2  A: 

Well, the short answer is to use a case-sensitive collation - the longer answer is don't store plaintext passwords in your database!

TML
A: 

You can use COLLATE clause in your T-SQL statement.

Ex.

SELECT * FROM dbo.TableName WHERE Password = @ password COLLATE SQL_Latin1_General_CP1_CS_AS
Gordian Yuan
Lets' hope they use the "Latin1_General_BIN" collation in their actual solution and not a legacy SQL collation...
gbn