Skip to content

Commit

Permalink
Add support of argon2i & argon2id password hash types
Browse files Browse the repository at this point in the history
Closes pull-request #158
  • Loading branch information
brenard authored and leenooks committed Aug 5, 2022
1 parent 9488fe2 commit 43bac58
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/config.php.example
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
'ssha512'=>'ssha512',
'sha256crypt'=>'sha256crypt',
'sha512crypt'=>'sha512crypt',
'argon2i'=>'argon2i',
'argon2id'=>'argon2id',
)*/
# $config->custom->password['available_types'] = array(''=>'clear','md5'=>'md5');

Expand Down
2 changes: 2 additions & 0 deletions lib/config_default.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ public function __construct() {
'ssha512'=>'ssha512',
'sha256crypt'=>'sha256crypt',
'sha512crypt'=>'sha512crypt',
'argon2i'=>'argon2i',
'argon2id'=>'argon2id',
));

/** Search display
Expand Down
32 changes: 32 additions & 0 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2299,6 +2299,20 @@ function pla_password_hash($password_clear,$enc_type) {

break;

case 'argon2i':
if (! defined('PASSWORD_ARGON2I'))
error(_('Your system does not support argon2i encryption (PHP 7.2 or upper is required).'),'error','index.php');
$new_value = sprintf('{ARGON2}%s',password_hash($password_clear,PASSWORD_ARGON2I));

break;

case 'argon2id':
if (! defined('PASSWORD_ARGON2ID'))
error(_('Your system does not support argon2id encryption (PHP 7.3 or upper is required).'),'error','index.php');
$new_value = sprintf('{ARGON2}%s',password_hash($password_clear,PASSWORD_ARGON2ID));

break;

case 'clear':
default:
$new_value = $password_clear;
Expand Down Expand Up @@ -2534,6 +2548,14 @@ function password_check($cryptedpassword,$plainpassword,$attribute='userpassword

break;

# Argon2 crypted passwords
case 'argon2':
if (password_verify($plainpassword, $cryptedpassword))
return true;
else
return false;
break;

# No crypt is given assume plaintext passwords are used
default:
if ($plainpassword == $cryptedpassword)
Expand Down Expand Up @@ -2577,6 +2599,16 @@ function get_enc_type($user_password) {

elseif (preg_match('/{[^}]+}_+/',$user_password))
$enc_type = 'ext_des';

}
elseif (strcasecmp($enc_type,'argon2') == 0) {

if (preg_match('/{ARGON2}\$argon2i\$/',$user_password))
$enc_type = 'argon2i';

elseif (preg_match('/{ARGON2}\$argon2id\$/',$user_password))
$enc_type = 'argon2id';

}

return $enc_type;
Expand Down

0 comments on commit 43bac58

Please sign in to comment.