php密码加密速度较慢

WBOY
Release: 2016-06-06 20:17:03
Original
1540 people have browsed it

用户密码加密采用password_hash
先hash时间戳,再用hash后的值跟静态盐跟用户密码hash得到密码,
线上运行发现速度比较慢,最慢一次大约有2000ms,
有什么好的解决方案么?

回复内容:

用户密码加密采用password_hash
先hash时间戳,再用hash后的值跟静态盐跟用户密码hash得到密码,
线上运行发现速度比较慢,最慢一次大约有2000ms,
有什么好的解决方案么?

加盐md5即可, php自带的加密函数不利于跨平台

1.用MD5加密
2.PHP的几个常用加密函数:https://jellybool.com/post/php-encrypt-functions
3.自定义加密 // 百度很多的
4.PHP 标准AES加密算法类 http://www.oschina.net/code/snippet_99277_45148
github 一个php自定义加密的:
`

<code>require_once("xxtea.php");
$str = "Hello World! 你好,中国!";
$key = "1234567890";
$encrypt_data = xxtea_encrypt($str, $key);
$decrypt_data = xxtea_decrypt($encrypt_data, $key);
if ($str == $decrypt_data) {
    echo "success!";
} else {
    echo "fail!";
}</code>
Copy after login

?>`

https://github.com/xxtea/xxtea-php

可以让hash的逻辑在mysql里做,mysql有MD5函数、password函数,可以试试

问题找到了,password_hash会传入三个参数,最后一个参数是一个数组,里面有一个'cost'指定加密迭代次数,默认13即2^13次。将数改小之后速度提升明显。

如果你写个PHP扩展
如果你用Docker部署环境。

Related labels:
php
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!