passwordUtil.php 911 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. /**
  24. * Verify the given password is valid.
  25. *
  26. * A valid password is a string of at least 7 characters.
  27. *
  28. * @param string $password
  29. *
  30. * @return boolean True if the password is valid, false otherwise
  31. */
  32. public static function check($password) {
  33. return strlen($password) >= 7;
  34. }
  35. }