版本封存
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package totp_tier_one
|
||||
|
||||
import (
|
||||
otp "cmii-uav-watchdog-otp"
|
||||
"cmii-uav-watchdog-otp/totp"
|
||||
"time"
|
||||
)
|
||||
|
||||
var TierOneTOTPSecretOpts = totp.GenerateOpts{
|
||||
SecretSize: 64,
|
||||
Issuer: "cmii-uav-watchdog-center",
|
||||
AccountName: "cmii-uav-watchdog-center",
|
||||
Period: 30 * 2 * 30, // 30分钟
|
||||
Digits: otp.DigitsEight,
|
||||
Algorithm: otp.AlgorithmSHA256,
|
||||
}
|
||||
|
||||
// GenerateTierOneTOTPCode 生成一级TOTP验证码
|
||||
func GenerateTierOneTOTPCode(secret string) (string, error) {
|
||||
validateOpts := totp.ValidateOpts{}
|
||||
validateOpts.ConvertToValidateOpts(TierOneTOTPSecretOpts)
|
||||
|
||||
code, err := totp.GenerateCodeCustom(secret, time.Now(), validateOpts)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return code, nil
|
||||
}
|
||||
|
||||
// VerifyTierOneTOTPCode 验证一级TOTP验证码
|
||||
func VerifyTierOneTOTPCode(code string, secret string) bool {
|
||||
validateOpts := totp.ValidateOpts{}
|
||||
validateOpts.ConvertToValidateOpts(TierOneTOTPSecretOpts)
|
||||
valid, err := totp.ValidateCustom(code, secret, time.Now(), validateOpts)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return valid
|
||||
}
|
||||
Reference in New Issue
Block a user