Home  >  Article  >  Backend Development  >  PHP's phpass class encryption algorithm

PHP's phpass class encryption algorithm

WBOY
WBOYOriginal
2016-07-28 08:28:212579browse

Password encryption has been using the md5 method before. The md5 encrypted password can be forcibly cracked. Online searches found that the bcrypt algorithm can be used, which has a high security factor. Currently, both the YII framework and wordpress are using this algorithm.

phpass is an open source class library that allows us to conveniently use the bcrpt encryption algorithm

The download addresses are:

CSDN: http://download.csdn.net/detail/xiao_bai8/9565233

Official website: http ://www.openwall.com/phpass/

The specific implementation code is as follows:

// 引入类文件
require 'PasswordHash.php';

// 初始化散列器为不可移植,安全性更好。false加密字符串是60位,true加密字符是34位
$hasher = new PasswordHash(8, true);

// 执行加密
$hashedPassword = $hasher->HashPassword('test123');

// 输出加密后的字符和对应的字符串长度
echo $hashedPassword;
echo '<br>';
echo strlen($hashedPassword).'<br>';

// 检查密码是否正确,第一个参数是密码的明文,第二个是加密后的字符串
$hasher->CheckPassword('test123', $hashedPassword);  // false

$hasher->CheckPassword('test1234', $hashedPassword);  // true

The above introduces the phpass encryption algorithm of PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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