一,相关文档:
https://www.php.net/manual/zh/function.password-hash.php
二,php代码:
/*
*测试用bcrypt方式验证密码
*用password_hash 和 password_verify一对函数实现
* */
public function testPass() {
//原始密码
$origPass = "123456";
echo "origPass:".$origPass.":<br/>";
$bcryptPass = password_hash($origPass, PASSWORD_DEFAULT);
echo "password:".$bcryptPass.":<br/>";
//判断密码是否匹配
if (password_verify($origPass,$bcryptPass)) {
echo "密码正确";
} else {
echo "密码错误";
}
echo "<br/>";
if (password_verify("123321",$bcryptPass)) {
echo "密码正确";
} else {
echo "密码错误";
}
}
说明:刘宏缔的架构森林—专注it技术的博客,
网址:https://imgtouch.com
本文: https://blog.imgtouch.com/index.php/2023/11/01/php-bcrypt-jia-mi-he-yan-zheng/
代码: https://github.com/liuhongdi/ 或 https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
三,测试效果
四,查看php的版本:
liuhongdi@lhdpc:/data/laravel/dignews$ php --version PHP 8.1.1 (cli) (built: Dec 20 2021 16:12:16) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.1, Copyright (c) Zend Technologies