postfixadmin / password-hashing
生成密码散列的例程,适用于 Dovecot 或 Courier 邮件服务器
0.0.1
2021-10-02 19:03 UTC
Requires
- php: >=7.2
Requires (Dev)
- friendsofphp/php-cs-fixer: *
- phpunit/phpunit: ^8|^9
- vimeo/psalm: ^4.8
README
创建各种密码散列的独立 PHP 库
注意,此库仍然相当新(2021/07/02)。在审查过程中,很可能需要进行重大重构/重命名。
支持机制(散列格式)
查看
第 12 行在 46ddd21
public const SUPPORTED = [ |
某些机制支持以 HEX (.HEX) 编码或 BASE64 (.B64) 编码的输出。
目前
- SHA1, SHA1.HEX, SHA1.B64
- SSHA
- SSHA512
- BLF-CRYPT, BLF-CRYPT.B64
- SHA512-CRYPT, SHA512-CRYPT.B64
- ARGON2I, ARGON2I.B64
- ARGON2ID, ARGON2ID.B64
- SHA256, SHA256-CRYPT, SHA256-CRYPT.B64
- SHA512, SHA512.B64
- MD5-CRYPT, MD5
- PLAIN-MD5
- CRYPT ({CRYPT} 前缀,默认使用 Blowfish)
- SYSTEM (DES CRYPT,最好避免)
- PLAIN, CLEAR, CLEARTEXT (用于测试的有用)
- COURIER:MD5
- COURIER:MD5RAW
- COURIER:SSHA (与 SSHA 相同)
- COURIER:SHA256 (与 SHA256 相同)
示例用法
主要功能反映了 PostfixAdmin 中的传统行为,有一个 'pacrypt' 函数,当给定 ...
- 一个参数 - 明文密码 - 返回一个散列。
- 两个参数 - 明文密码和存储的散列 - 如果返回值与存储的散列匹配,则明文密码与我们的散列匹配。
$tool = new \PostfixAdmin\PasswordHashing\Crypt('ARGON2I'); // should output something to indicate what your system supports (may be dependent on PHP variant, PHP modules etc) $hash = $tool->crypt('fishbeans'); echo "Hash is: $hash \n"; echo "Verify: " . json_encode($hash == $tool->crypt('fishbeans', $hash)) . "\n"; echo "Verify fails with: " . json_encode('cat' == $tool->crypt('fishbeans', $hash)) . "\n";
上面的代码将输出类似以下内容
Hash is: {ARGON2I}$argon2i$v=19$m=65536,t=4,p=1$d1JMUXVHSUtLTGhxYnowVQ$4raz6DDUbtRysi+1ZTdNL3L5j4tcSYnzWxyLVDtFjKc
Verify: true
Verify fails with: false
变更日志
2021/07/03 - 初始发布 / 从 https://github.com/postfixadmin/postfixadmin ...