Forum Moderators: coopster

Message Too Old, No Replies

problem decrypting md5 encrypted password

crypt() used

         

An156

2:57 pm on Mar 24, 2009 (gmt 0)

10+ Year Member



i used this code for encrypting the password

$passwd = crypt('$pass' , '$1$d4juhy6d$');

all is fine, passwd is stored in encrypted form in database
but when i'm try to check it wid the passwd entered by the user while login.. it creating problems

here is the code...

if(crypt('$pass', '$rs')=='$1$d4juhy6d$')
{echo 'gud';}
else
{echo 'bad';}
----------------------------------------------
i tried this also

if(crypt('$pass', '$1$d4juhy6d$')=='$rs')
{echo 'gud';}
else
{echo 'bad';}

$rs=retrieved passwd frm the database
$pass=passwd entered by the user

$1$d4juhy6d$ is the encryption code for md5

Please suggest!
Thanks in advance
Anand

d40sithui

4:43 pm on Mar 24, 2009 (gmt 0)

10+ Year Member



The issue here is using single quotes. Everything in single quotes will not be evaluated, so you're really encrypting the string '$pass' rather than the actual value of $pass. And then when you try to compare to the value in the database $rs, you're really comparing to '$rs' rather than the value of $rs, which will always yield false.


$passwd = crypt('$pass' , '$1$d4juhy6d$');

is not the same as

$passwd = crypt($pass , '$1$d4juhy6d$');

eelixduppy

4:45 pm on Mar 24, 2009 (gmt 0)




if(crypt('$pass', '$1$d4juhy6d$')=='$rs')

This isn't going to work because of the single quotes that you are using with the variable $pass and $rs. Try the following and see if it helps:


if(crypt($pass, '$1$d4juhy6d$') == $rs)

Notice the placement of the single quotes I have there.

Also for additional information about strings, you can refer to the documentation here: [php.net...]

[edit]
Too slow ;)

An156

6:23 pm on Mar 24, 2009 (gmt 0)

10+ Year Member



hey
i tried wat u explained to me i.e

if(crypt($pass, '$1$d4juhy6d$') == $rs)

but still the same problem
need help!

eelixduppy

6:39 pm on Mar 24, 2009 (gmt 0)



Print out both values and compare them visually:

echo crypt($pass, '$1$d4juhy6d$');
echo $rs;

See if there is anything that doesn't belong there or perhaps if there is anything else that doesn't seem like expected behavior.

eeek

11:03 pm on Mar 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are you abolutely certain you are using the same salt? Are you using the same encryption algorithm?

An156

3:35 pm on Mar 25, 2009 (gmt 0)

10+ Year Member



hey all.. problem solved! actually while storing the the passwd in the database i was using the passwd variable in quotes under the crypt function().. he he it was really a silly mistake :)

Thank you guyz for all ur support!