diff --git a/functions.inc.php b/functions.inc.php index ff6a50d3..3e8e3304 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1299,24 +1299,35 @@ function pacrypt($pw, $pw_db = "") $mechanism = $CONF['encrypt'] ?? 'CRYPT'; - if ($mechanism == 'php_crypt') { + $mechanism = strtoupper($mechanism); + + $crypts = ['PHP_CRYPT', 'MD5CRYPT', 'PHP_CRYPT:DES', 'PHP_CRYPT:MD5', 'PHP_CRYPT:SHA256']; + + if (in_array($mechanism, $crypts)) { $mechanism = 'CRYPT'; } - if ($mechanism == 'php_crypt:SHA512') { + if ($mechanism == 'PHP_CRYPT:SHA512') { $mechanism = 'SHA512-CRYPT'; } - if(preg_match('/^dovecot:(.*)$/i', $mechanism, $matches)) { + if($mechanism == 'SHA512.B64') { + $mechanism = 'SHA512-CRYPT.B64'; + } + + if(preg_match('/^DOVECOT:(.*)$/i', $mechanism, $matches)) { $mechanism = strtoupper($matches[1]); } - if(preg_match('/^courier:(.*)$/i', $mechanism, $matches)) { + if(preg_match('/^COURIER:(.*)$/i', $mechanism, $matches)) { $mechanism = strtoupper($mechanism); } if (empty($pw_db)) { $pw_db = null; } + if($mechanism == 'AUTHLIB') { + return _pacrypt_authlib($pw, $pw_db); + } $hasher = new \PostfixAdmin\PasswordHashing\Crypt($mechanism); return $hasher->crypt($pw, $pw_db); } diff --git a/tests/PacryptTest.php b/tests/PacryptTest.php index ac75be68..77b21ea4 100644 --- a/tests/PacryptTest.php +++ b/tests/PacryptTest.php @@ -313,7 +313,7 @@ EOF; 'cleartext' => 'test123', 'mysql_encrypt' => '$6$$KMCDSuWNoVgNrK5P1zDS12ZZt.LV4z9v9NtD0AG0T5Rv/n0wWVvZmHMSKKZQciP7lrqrlbrBrBd4lhBSGy1BU0', 'authlib' => '{md5raw}cc03e747a6afbbcbf8be7668acfebee5', - 'php_crypt:SHA512' => '$6$IeqpXtDIXF09ADdc$IsE.SSK3zuwtS9fdWZ0oVxXQjPDj834xqxTiv3Qfidq3AbAjPb0DNyI28JyzmDVlbfC9uSfNxD9RUyeO1.7FV/', + 'php_crypt:SHA512' => '{SHA512-CRYPT}$6$IeqpXtDIXF09ADdc$IsE.SSK3zuwtS9fdWZ0oVxXQjPDj834xqxTiv3Qfidq3AbAjPb0DNyI28JyzmDVlbfC9uSfNxD9RUyeO1.7FV/', 'php_crypt:DES' => 'VXAXutUnpVYg6', 'php_crypt:MD5' => '$1$rGTbP.KE$wimpECWs/wQa7rnSwCmHU.', 'php_crypt:SHA256' => '$5$UaZs6ZuaLkVPx3bM$4JwAqdphXVutFYw7COgAkp/vj09S1DfjIftxtjqDrr/',