mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-14 16:44:39 +00:00
auth: tweak previous, hide implementation details; closes #1282
This commit is contained in:
parent
2a025de404
commit
bd2d28c622
@ -488,14 +488,16 @@ function local_user_del($user)
|
||||
|
||||
function local_user_set_password(&$user, $password)
|
||||
{
|
||||
$user['password'] = generate_password_hash($password, 10);
|
||||
$cost = 10;
|
||||
|
||||
// Converts ascii to unicode.
|
||||
$astr = (string) $password;
|
||||
$ustr = '';
|
||||
for ($i = 0; $i < strlen($astr); $i++) {
|
||||
$a = ord($astr{$i}) << 8;
|
||||
$ustr.= sprintf("%X", $a);
|
||||
$hash = password_hash($password, PASSWORD_BCRYPT, [ 'cost' => $cost ]);
|
||||
if ($hash !== false) {
|
||||
/*
|
||||
* $2y$ returned is supported in FreeBSD 11.0 and up,
|
||||
* but we started with FreeBSD 10.3 so need to fix:
|
||||
*/
|
||||
$hash[2] = 'b';
|
||||
$user['password'] = $hash;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1575,11 +1575,3 @@ function is_install_media()
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function generate_password_hash($password, $cost = 10)
|
||||
{
|
||||
$hash = password_hash($password, PASSWORD_BCRYPT, ["cost" => $cost]);
|
||||
// at the moment of writing FreeBSD can't recognise $2y$... as bcrypt, $2b$ is needed
|
||||
$hash[2] = 'b';
|
||||
return $hash;
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ if (isset($_POST['save'])) {
|
||||
|
||||
if (count($input_errors) == 0) {
|
||||
// all values are okay --> saving changes
|
||||
$config['system']['user'][$userindex[$username]]['password'] = generate_password_hash($_POST['passwordfld1'], 10);
|
||||
local_user_set_password($config['system']['user'][$userindex[$username]], $_POST['passwordfld1']);
|
||||
local_user_set($config['system']['user'][$userindex[$username]]);
|
||||
|
||||
write_config();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user