Add hash support for ssha512

This commit is contained in:
Bert Van de Poel 2021-04-24 04:02:56 +02:00 committed by Deon George
parent 54bb4743aa
commit bc1691f5d2

View File

@ -2171,6 +2171,7 @@ function password_types() {
'sha384'=>'sha384', 'sha384'=>'sha384',
'ssha384'=>'ssha384', 'ssha384'=>'ssha384',
'sha512'=>'sha512', 'sha512'=>'sha512',
'ssha512'=>'ssha512',
'sha256crypt'=>'sha256crypt', 'sha256crypt'=>'sha256crypt',
'sha512crypt'=>'sha512crypt', 'sha512crypt'=>'sha512crypt',
); );
@ -2320,6 +2321,12 @@ function pla_password_hash($password_clear,$enc_type) {
break; break;
case 'ssha512':
$salt = hex2bin(random_salt(8));
$new_value = sprintf('{SSHA512}%s', base64_encode(hash('sha512', $password_clear.$salt, true).$salt));
break;
case 'sha256crypt': case 'sha256crypt':
if (! defined('CRYPT_SHA256') || CRYPT_SHA256 == 0) if (! defined('CRYPT_SHA256') || CRYPT_SHA256 == 0)
error(_('Your system crypt library does not support sha256crypt encryption.'),'error','index.php'); error(_('Your system crypt library does not support sha256crypt encryption.'),'error','index.php');
@ -2568,6 +2575,19 @@ function password_check($cryptedpassword,$plainpassword,$attribute='userpassword
break; break;
# Salted SHA512 crypted passwords
case 'ssha512':
$hash = base64_decode($cryptedpassword);
$salt = substr($hash,64);
$new_hash = base64_encode(hash('sha512', $plainpassword.$salt, true).$salt);
if (strcmp($cryptedpassword,$new_hash) == 0)
return true;
else
return false;
break;
# No crypt is given assume plaintext passwords are used # No crypt is given assume plaintext passwords are used
default: default:
if ($plainpassword == $cryptedpassword) if ($plainpassword == $cryptedpassword)