问题描述
我可以使用 Google 身份验证器生成代码。但它默认生成一个 6 位代码。有什么办法可以设置成4位数?
我试过了,但没有得到我预期的结果。
var generatedCode = $"otpauth://totp/{host}:{email}?secret={secretKey}&issuer={host}&digits=4";
解决方法
查看 open source version of the Google Authenticator Android app,不支持除 6 以外的任何数字。解释 otpauth URI 的 parseSecret
方法从不读取 digits
查询段,只读取 {{ 1}} 和 secret
。而 issuer
类有
OtpProvider
它被传递到 private static final int PIN_LENGTH = 6; // HOTP or TOTP
— 它是一个内置常量,不是用户控制的。