Skip to content

Commit 43bac58

Browse files
brenardleenooks
authored andcommitted
Add support of argon2i & argon2id password hash types
Closes pull-request #158
1 parent 9488fe2 commit 43bac58

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

config/config.php.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
'ssha512'=>'ssha512',
9494
'sha256crypt'=>'sha256crypt',
9595
'sha512crypt'=>'sha512crypt',
96+
'argon2i'=>'argon2i',
97+
'argon2id'=>'argon2id',
9698
)*/
9799
# $config->custom->password['available_types'] = array(''=>'clear','md5'=>'md5');
98100

lib/config_default.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,8 @@ public function __construct() {
576576
'ssha512'=>'ssha512',
577577
'sha256crypt'=>'sha256crypt',
578578
'sha512crypt'=>'sha512crypt',
579+
'argon2i'=>'argon2i',
580+
'argon2id'=>'argon2id',
579581
));
580582

581583
/** Search display

lib/functions.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,6 +2299,20 @@ function pla_password_hash($password_clear,$enc_type) {
22992299

23002300
break;
23012301

2302+
case 'argon2i':
2303+
if (! defined('PASSWORD_ARGON2I'))
2304+
error(_('Your system does not support argon2i encryption (PHP 7.2 or upper is required).'),'error','index.php');
2305+
$new_value = sprintf('{ARGON2}%s',password_hash($password_clear,PASSWORD_ARGON2I));
2306+
2307+
break;
2308+
2309+
case 'argon2id':
2310+
if (! defined('PASSWORD_ARGON2ID'))
2311+
error(_('Your system does not support argon2id encryption (PHP 7.3 or upper is required).'),'error','index.php');
2312+
$new_value = sprintf('{ARGON2}%s',password_hash($password_clear,PASSWORD_ARGON2ID));
2313+
2314+
break;
2315+
23022316
case 'clear':
23032317
default:
23042318
$new_value = $password_clear;
@@ -2534,6 +2548,14 @@ function password_check($cryptedpassword,$plainpassword,$attribute='userpassword
25342548

25352549
break;
25362550

2551+
# Argon2 crypted passwords
2552+
case 'argon2':
2553+
if (password_verify($plainpassword, $cryptedpassword))
2554+
return true;
2555+
else
2556+
return false;
2557+
break;
2558+
25372559
# No crypt is given assume plaintext passwords are used
25382560
default:
25392561
if ($plainpassword == $cryptedpassword)
@@ -2577,6 +2599,16 @@ function get_enc_type($user_password) {
25772599

25782600
elseif (preg_match('/{[^}]+}_+/',$user_password))
25792601
$enc_type = 'ext_des';
2602+
2603+
}
2604+
elseif (strcasecmp($enc_type,'argon2') == 0) {
2605+
2606+
if (preg_match('/{ARGON2}\$argon2i\$/',$user_password))
2607+
$enc_type = 'argon2i';
2608+
2609+
elseif (preg_match('/{ARGON2}\$argon2id\$/',$user_password))
2610+
$enc_type = 'argon2id';
2611+
25802612
}
25812613

25822614
return $enc_type;

0 commit comments

Comments
 (0)