普贤教程 › 包参考
passhash 包
密码哈希(PBKDF2-HMAC-SHA256)
| 项 | 值 |
|---|---|
| 包名 | passhash |
| 版本 | 0.2.0 |
| 可用版本 | 0.1.0 / 0.2.0 |
| 入口 | passhash.px |
| 分类 | 认证与安全 |
| 文件数 / 行数 | 1 / 126 |
安装与引入
bash
pxpkg init # 首次 pxpkg add passhash@0.2.0 pxpkg install
px
import passhash所属分类教程:认证与安全
公开接口
| 函数 | 参数 |
|---|---|
pass_hash | pw, salt=null, iters=PH_DEFAULT_ITERS |
pass_verify | pw, stored |
其余 9 个 def(内部与辅助,可直接调用但不属稳定接口)
| 函数 | 参数 |
|---|---|
ph_iters | stored |
ph_salt | stored |
ph_hash_body | stored |
ph_algorithm | stored |
ph_info | stored |
ph_needs_rehash | stored, target_iters |
ph_const_eq | a, b |
ph_verify | pw, stored |
ph_hash_with | pw, iters |
包内说明(源码头注释)
text
============================================================ 普贤生态库:registry/passhash —— 密码哈希(PBKDF2-HMAC-SHA256) ------------------------------------------------------------ 纯函数库(无 IO、无状态),编译(px build)与解释(px run)双模式一致。 pass_hash(pw, salt?, iters?) → Ok("pbkdf2$iters$salt_hex$hash_hex") pass_verify(pw, stored) → bool 存储格式(自解释,便于轮换参数): pbkdf2$<迭代次数>$<salt hex>$<hash hex> 安全考虑: - 默认 10,000 次迭代(低端设备可接受;生产建议 100k+,可调) - salt 默认 os_random_hex(16)(32 hex = 128 bit) - 底层 pbkdf2_sha256 为 runtime 原生(原始字节) ============================================================