Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function hexToAscii($hex)
- {
- $strLength = strlen($hex);
- $returnVal = '';
- for($i=0; $i<$strLength; $i += 2)
- {
- $dec_val = hexdec(substr($hex, $i, 2));
- $returnVal .= chr($dec_val);
- }
- return $returnVal;
- }
- function HashedPassword($plainpassword)
- {
- // generating a random salt
- $salt_hex = substr(sha1(uniqid()),18,8);
- $salt_ascii = hexToAscii($salt_hex);
- $hashpassword = hash('sha256', $plainpassword . $salt_ascii);
- $returnVal = "{SSHA256.HEX}" . $hashpassword . $salt_hex;
- return $returnVal;
- }
- function VerifyHashedPassword($encodedpassword,$plainpassword)
- {
- if(stripos($encodedpassword,'SSHA256'))
- {
- $encodedpassword = substr($encodedpassword,13,strlen($encodedpassword));
- }
- $lengthstring = strlen($encodedpassword);
- $salt_hex = substr($encodedpassword, $lengthstring - 8, 8);
- $salt_ascii = hexToAscii($salt_hex);
- $newpasswordhash = hash('sha256', $plainpassword . $salt_ascii );
- $newencodedpassword = $newpasswordhash . $salt_hex;
- if ( "$encodedpassword" == "$newencodedpassword" ) {
- // if strings are equal, passwords supplied matches
- $returnVal = true;
- } else {
- // if strings are not equal, passwords do NOT match
- $returnVal = false;
- }
- return $returnVal;
- }
Add Comment
Please, Sign In to add comment