passwordUtil.php 653 B

12345678910111213141516171819202122232425
  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(#[\SensitiveParameter] string $passwordPlain): string {
  11. $passwordHash = password_hash(
  12. $passwordPlain,
  13. PASSWORD_BCRYPT,
  14. ['cost' => self::BCRYPT_COST]
  15. );
  16. return $passwordHash;
  17. }
  18. public static function cryptAvailable(): bool {
  19. $hash = '$2y$04$usesomesillystringfore7hnbRJHxXVLeakoG8K30oukPsA.ztMG';
  20. return $hash === @crypt('password', $hash);
  21. }
  22. }