加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

为什么php的password_hash这么慢?

发布时间:2020-12-13 13:13:39 所属栏目:PHP教程 来源:网络整理
导读:我正在使用password_hash进行密码加密.但是有一个奇怪的问题,password_hash花费很长时间.这是一个示例代码. 这段代码将耗费1秒以上.是正常吗 ?php $startTime = microtime(TRUE); $password='123456'; $cost=13; $hash=password_hash($password,PASSWORD_DEF
我正在使用password_hash进行密码加密.但是有一个奇怪的问题,password_hash花费很长时间.这是一个示例代码.
这段代码将耗费1秒以上.是正常吗
<?php
  $startTime = microtime(TRUE);
  $password='123456';
  $cost=13;
  $hash=password_hash($password,PASSWORD_DEFAULT,['cost' => $cost]);
  password_verify($password,$hash);
  $endTime = microtime(TRUE);
  $time = $endTime - $startTime;
  echo $time;
?>

结果是:1.0858609676361

运行在 3v4l这似乎完全正常.

密码哈希不是你想要的优化.用Leigh on the hash documentation:

If you are hashing passwords etc for security,speed is not your friend. You should use the slowest method.

Slow to hash means slow to crack and will hopefully make generating things like rainbow tables more trouble than it’s worth.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读