You are here

public static function ParagonIE_Sodium_Compat::crypto_pwhash_str_needs_rehash in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/paragonie/sodium_compat/src/Compat.php \ParagonIE_Sodium_Compat::crypto_pwhash_str_needs_rehash()

Do we need to rehash this password?

Parameters

string $hash:

int $opslimit:

int $memlimit:

Return value

bool

Throws

SodiumException

1 call to ParagonIE_Sodium_Compat::crypto_pwhash_str_needs_rehash()
php72compat.php in vendor/paragonie/sodium_compat/lib/php72compat.php

File

vendor/paragonie/sodium_compat/src/Compat.php, line 1987

Class

ParagonIE_Sodium_Compat

Code

public static function crypto_pwhash_str_needs_rehash($hash, $opslimit, $memlimit) {
  ParagonIE_Sodium_Core_Util::declareScalarType($hash, 'string', 1);
  ParagonIE_Sodium_Core_Util::declareScalarType($opslimit, 'int', 2);
  ParagonIE_Sodium_Core_Util::declareScalarType($memlimit, 'int', 3);

  // Just grab the first 4 pieces.
  $pieces = explode('$', (string) $hash);
  $prefix = implode('$', array_slice($pieces, 0, 4));

  // Rebuild the expected header.

  /** @var int $ops */
  $ops = (int) $opslimit;

  /** @var int $mem */
  $mem = (int) $memlimit >> 10;
  $encoded = self::CRYPTO_PWHASH_STRPREFIX . 'v=19$m=' . $mem . ',t=' . $ops . ',p=1';

  // Do they match? If so, we don't need to rehash, so return false.
  return !ParagonIE_Sodium_Core_Util::hashEquals($encoded, $prefix);
}