Topic: PHP Password encryption and login
Hi,
Today looking the forum I found different post for this topic but no one with a good solution, so I dedicated a couple of hours for to find a solutions.
The SHA512 pw is created in this way:
$password='test'; $salt=random_str(8);
$password_to_db="{SSHA512}".base64_encode(hash('sha512',$password.$salt,true).$salt);
That means that you cannot do the login without to read before the hashed pw from DB for to extract the $salt
So after had read the data from DB you may determinate le new hash i this way
$password='test12345';
$hashfromdb="{SSHA512}R7Agj9845.....";
$pwslt=substr($letta,9,strlen($letta)-9); # Cut the first 9 chars {SSHA512}
$pwslt=base64_decode($pwslt); # Decode the rest from base64
$pws=substr($pwslt,0,64); # Separate the hash (first 512 bit > 64 chars)
$slt=substr($pwslt,64,strlen($pwslt)-64); # Separate the used salt
$hashtodb="{SSHA512}".base64_encode(hash('sha512',$pwchiara.$slt,true).$slt); # Calculate the new hash
So now you have to use $hashtodb in the select for the password
I hope it will be usefull for someone.
Have a nice day
----
Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.