Home >Backend Development >PHP Problem >How to use php password_verify function

How to use php password_verify function

藏色散人
藏色散人Original
2019-05-26 10:42:544913browse

php password_verify函数用于验证密码是否和散列值匹配,其语法是bool password_verify ( string $password , string $hash ),参数password指用户的密码,hash指一个由password_hash()创建的散列值。

How to use php password_verify function

php password_verify函数怎么用?

password_verify() 函数用于验证密码是否和散列值匹配。

PHP 版本要求: PHP 5 >= 5.5.0, PHP 7

语法

bool password_verify ( string $password , string $hash )

参数说明:

password: 用户的密码。

hash: 一个由 password_hash() 创建的散列值。

返回值

如果密码和散列值匹配则返回 TRUE,否则返回 FALSE 。

实例

password_verify() 用法

<?php
// 想知道以下字符从哪里来,可参见 password_hash() 的例子
$hash = &#39;$2y$07$BCryptRequires22Chrcte/VlQH0piJtjXl.0t1XkA8pw9dMXTpOq&#39;;
 
if (password_verify(&#39;rasmuslerdorf&#39;, $hash)) {
    echo &#39;Password is valid!&#39;;
} else {
    echo &#39;Invalid password.&#39;;
}
?>

输出结果为:

Password is valid!

The above is the detailed content of How to use php password_verify function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn