px普贤教程PuXian
普贤教程 › 包参考

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_hashpw, salt=null, iters=PH_DEFAULT_ITERS
pass_verifypw, stored
其余 9 个 def(内部与辅助,可直接调用但不属稳定接口)
函数参数
ph_itersstored
ph_saltstored
ph_hash_bodystored
ph_algorithmstored
ph_infostored
ph_needs_rehashstored, target_iters
ph_const_eqa, b
ph_verifypw, stored
ph_hash_withpw, 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 原生(原始字节)
============================================================