ponepaste/includes/passwords.php

25 lines
664 B
PHP
Raw Normal View History

<?php
require_once(__DIR__ . '/config.php');
function pp_password_hash(string $password) : string {
2021-07-17 12:33:08 -04:00
return 'P' . password_hash($password . PP_PASSWORD_PEPPER, PASSWORD_BCRYPT);
}
2021-07-17 12:33:08 -04:00
function pp_password_verify(string $password, string $hash, bool &$needs_rehash = null) : bool {
/* New, peppered hash. */
if ($hash[0] === 'P') {
2021-07-17 12:33:08 -04:00
if ($needs_rehash !== null) {
$needs_rehash = false;
}
return password_verify($password . PP_PASSWORD_PEPPER, substr($hash, 1));
}
/* Old, unpeppered hash. */
2021-07-17 12:33:08 -04:00
if ($needs_rehash !== null) {
$needs_rehash = true;
}
return password_verify($password, $hash);
}