views:

218

answers:

2

Hi,

I implemented a custom membership provider in ASP.net MVC, and can't figure out how to make the username non case-sensitive at signin. So, for example, "Solomon" could log in, but "solomon" could not.

My implementation is very bare bones. I basically just wrote code for ValidateUser(), and Change Password().

Thanks for the help!

A: 

Convert the username to its lowercase version, and then compare it to the lowercase version of the username in the database. The ANSI SQL would be:

WHERE LOWER(username) = :username

Supply the username parameter as:

... = username.ToLower();
Michael Shimmins
I prefer upper case :)
Lex Li
You have a brittle logical dependency here, shimms. You should not split a logical operation. This should be an atomic comparison in the database/query.
Sky Sanders
+2  A: 

shimms is halfway there.

Splitting a logical operation between two 'tiers' is not a sound practice.

A logical operation should be atomic. So just lower both in the query...

e.g.

where Lower(username)=Lower(@username)
Sky Sanders
You're quite right. +1
Michael Shimmins
Awesome, thanks!
Solomon