From ee9034f24c530d27a752a4402c73aae4a69907be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Sat, 8 Oct 2016 21:24:33 +0200 Subject: [PATCH] add support for SHA-256 and SHA-512 via crypt(3) --- lib/functions.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/functions.php b/lib/functions.php index 96311ba..5adfc76 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -2116,6 +2116,8 @@ function password_types() { 'smd5'=>'smd5', 'ssha'=>'ssha', 'sha512'=>'sha512', + 'sha256crypt'=>'sha256crypt', + 'sha512crypt'=>'sha512crypt', ); } @@ -2124,7 +2126,8 @@ function password_types() { * * @param string The password to hash in clear text. * @param string Standard LDAP encryption type which must be one of - * crypt, ext_des, md5crypt, blowfish, md5, sha, smd5, ssha, sha512, or clear. + * crypt, ext_des, md5crypt, blowfish, md5, sha, smd5, ssha, sha512, + * sha256crypt, sha512crypt, or clear. * @return string The hashed password. */ function pla_password_hash($password_clear,$enc_type) { @@ -2227,6 +2230,20 @@ function pla_password_hash($password_clear,$enc_type) { break; + case 'sha256crypt': + if (! defined('CRYPT_SHA256') || CRYPT_SHA256 == 0) + error(_('Your system crypt library does not support sha256crypt encryption.'),'error','index.php'); + $new_value = sprintf('{CRYPT}%s',crypt($password_clear,'$5$'.random_salt(8))); + + break; + + case 'sha512crypt': + if (! defined('CRYPT_SHA512') || CRYPT_SHA512 == 0) + error(_('Your system crypt library does not support sha512crypt encryption.'),'error','index.php'); + $new_value = sprintf('{CRYPT}%s',crypt($password_clear,'$6$'.random_salt(8))); + + break; + case 'clear': default: $new_value = $password_clear;