rsthn / rose-otp
Rose OTP 适配器
1.0.6
2022-07-20 03:51 UTC
Requires
- php: ^8.1
- rsthn/rose-extension-installer: *
- spomky-labs/otphp: ^11.0
README
为 Rose 添加 TOTP/HOTP 支持,使用 Spomky-Labs 的优秀库 otphp 来创建密钥和一次性令牌。
安装
composer require rsthn/rose-otp
配置部分:OTP
表达式函数
otp::create
创建一个新的密钥,稍后用于生成一次性密码。输出是一个 64 字节的随机字符串,稍后转换为 Base32,结果是一个最大长度为 128 个字符的字符串,应存储在安全的地方以供以后使用。
OTP 设置来自 OTP 配置部分。
(set secretKey (otp::create))
otp::get secretKey:string [tokenTime:integer]
根据密钥返回当前基于时间的令牌。可以用来通过安全的手段如电子邮件、短信或自定义应用程序向用户展示。尽管如果用户有如 Google Authenticator 或 Authy 这样的身份验证应用程序,建议使用 otp::uri 函数。
(otp::get (secretKey))
otp::verify secretKey:string token:string
验证指定的令牌以检查其是否有效,返回布尔值。
(when-not (otp::verify (secretKey) "123123") (throw "OTP code is incorrect") )
otp::uri secretKey:string label:string [issuer:string]
返回用于 OTP 客户端(如 Authy 或 Google Authenticator)的 OTP-AUTH URI。
(otp::uri (secretKey) "Zork")