How to use php password_verify function

藏色散人
Release: 2023-02-22 19:10:02
Original
4869 people have browsed it

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 )
Copy after login

参数说明:

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;;
}
?>
Copy after login

输出结果为:

Password is valid!
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!