Files
FreshRSS/app/Utils/passwordUtil.php
Marien Fressinaud d0f1f9f141 Separate the update API password endpoint (#2675)
* Extract hashPassword method from userController

* Extract and refactor fever key-related methods

* Move update of API password to dedicated action

* Simplify the controller by refactoring feverUtil

* Add locales
2019-12-03 23:11:06 +01:00

28 lines
615 B
PHP

<?php
class FreshRSS_password_Util {
// Will also have to be computed client side on mobile devices,
// so do not use a too high cost
const BCRYPT_COST = 9;
/**
* Return a hash of a plain password, using BCRYPT
*
* @param string
* @return string
*/
public static function hash($passwordPlain) {
$passwordHash = password_hash(
$passwordPlain,
PASSWORD_BCRYPT,
array('cost' => self::BCRYPT_COST)
);
$passwordPlain = '';
// Compatibility with bcrypt.js
$passwordHash = preg_replace('/^\$2[xy]\$/', '\$2a\$', $passwordHash);
return $passwordHash == '' ? '' : $passwordHash;
}
}