Re: Case sensitive password

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



i hate posting the same answer to a given question thats already been
posted, but i had this all typed in when chris submitted his answer, so here
it is again..

On Wed, Jun 18, 2008 at 10:36 PM, R.C. <rme@xxxxxxxxxxxxxxxxxxx> wrote:

> I have coded a php page that accepts a password.  What is the code to make
> sure the password entered is NOT case-sensitive?


when you store the password, you can store it as all upper or all lowercase,
then when comparing against the stored value, do the same operation to the
value supplied from the user, and compare those.  and you dont have to
modify the original value if you dont want to, when you store it.  just
remember to alter both the stored value and the user-supplied value when
doing comparisons.

/// here is an example comparison
// get password value from db for user, put it in $storedPassword
// suppose the value the user supplied in a form is in variable
$userSuppliedPassword
// now for the case insensitive comparison
if(strtolower($storedPassword) == strtolower($userSuppliedPassword))
  // passwords are the same
else
  // passwords are different

also note in the above example, there is no encryption of the password,
which you almost certainly want to have ;)

-nathan

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux