passwordUtil.php 615 B

123456789101112131415161718192021222324252627
  1. <?php
  2. class FreshRSS_password_Util {
  3. // Will also have to be computed client side on mobile devices,
  4. // so do not use a too high cost
  5. const BCRYPT_COST = 9;
  6. /**
  7. * Return a hash of a plain password, using BCRYPT
  8. *
  9. * @param string
  10. * @return string
  11. */
  12. public static function hash($passwordPlain) {
  13. $passwordHash = password_hash(
  14. $passwordPlain,
  15. PASSWORD_BCRYPT,
  16. array('cost' => self::BCRYPT_COST)
  17. );
  18. $passwordPlain = '';
  19. // Compatibility with bcrypt.js
  20. $passwordHash = preg_replace('/^\$2[xy]\$/', '\$2a\$', $passwordHash);
  21. return $passwordHash == '' ? '' : $passwordHash;
  22. }
  23. }