password_needs_rehash

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

password_needs_rehash — 주어진 해시가 주어진 옵션과 일치하는지 확인


설명

password_needs_rehash(string $hash, string|int|null $algo, array $options = []): bool

이 함수는 제공된 해시가 제공된 알고리즘과 옵션을 구현하는지 확인합니다. 그렇지 않은 경우 해시를 다시 해시해야 한다고 가정합니다.


매개변수

hash
password_hash()에 의해 생성된 해시입니다.
algo
암호를 해시할 때 사용할 알고리즘을 나타내는 암호 알고리즘 상수입니다.
options
옵션을 포함하는 연관 배열입니다. 각 알고리즘에 대해 지원되는 옵션에 대한 문서는 암호 알고리즘 상수를 참조하십시오.

반환 값

주어진 algooptions과 일치하도록 해시를 다시 해시해야 하는 경우 true를 반환하고 그렇지 않은 경우 false를 반환합니다.


변경 로그

버전 설명
7.4.0 algo 매개변수는 이제 문자열을 예상하지만 이전 버전과의 호환성을 위해 여전히 int를 허용합니다.

Examples

예제 #1 password_needs_rehash() 사용

                  
<?php

$password = 'rasmuslerdorf';
$hash = '$2y$10$YCFsG6elYca568hBi2pZ0.3LDL5wjgxct1N8w/oLR/jfHsiQwCqTS';

// The cost parameter can change over time as hardware improves
$options = array('cost' => 11);

// Verify stored hash against plain-text password
if (password_verify($password, $hash)) {
    // Check if a newer hashing algorithm is available
    // or the cost has changed
    if (password_needs_rehash($hash, PASSWORD_DEFAULT, $options)) {
        // If so, create a new hash, and replace the old one
        $newHash = password_hash($password, PASSWORD_DEFAULT, $options);
    }

    // Log user in
}
?>