netsilik / peppered-passwords
在(BCrypt)散列之前使用HMAC进行安全的密码散列。
2.0.0
2021-01-26 13:10 UTC
Requires
- php: ^7.0 || ^8.0
This package is auto-updated.
Last update: 2024-09-26 21:18:50 UTC
README
在(BCrypt)散列之前使用HMAC进行安全的密码散列。
MIT许可
除非适用法律或书面同意要求,否则在许可下分发的软件按“原样”分发,不提供任何明示或暗示的保证或条件。
联系方式:info@netsilik.nl
最新版本可在以下地址获取:https://gitlab.com/Netsilik/PepperedPasswords
安装
composer require netsilik/peppered-passwords
使用方法
散列新密码
<?php
namespace My\Name\Space;
use Netsilik\Lib\PepperedPasswords;
$pepper = hex2bin(env('PEPPER')); // The binary pepper value, stored as a hexadecimal string
$hasher = new PepperedPasswords($pepper);
$hash = $hasher->hash($new_plaintext_password); // Story $hash in the user's record
验证密码
<?php
namespace My\Name\Space;
use Netsilik\Lib\PepperedPasswords;
$pepper = hex2bin(env('PEPPER')); // The binary pepper value, stored as a hexadecimal string
$hasher = new PepperedPasswords($pepper);
if ($hasher->verify($new_plaintext_password, $hash)) { // $hash retrieved from the user's record
echo 'Password ok.';
} else {
echo 'Wrong credentials.';
}