passwordUtil.php 731 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. declare(strict_types=1);
  3. class FreshRSS_password_Util {
  4. // Will also have to be computed client side on mobile devices,
  5. // so do not use a too high cost
  6. public const BCRYPT_COST = 9;
  7. /**
  8. * Return a hash of a plain password, using BCRYPT
  9. */
  10. public static function hash(string $passwordPlain): string {
  11. $passwordHash = password_hash(
  12. $passwordPlain,
  13. PASSWORD_BCRYPT,
  14. ['cost' => self::BCRYPT_COST]
  15. );
  16. return $passwordHash;
  17. }
  18. /**
  19. * Verify the given password is valid.
  20. *
  21. * A valid password is a string of at least 7 characters.
  22. *
  23. * @return bool True if the password is valid, false otherwise
  24. */
  25. public static function check(string $password): bool {
  26. return strlen($password) >= 7;
  27. }
  28. }