Skip to content

Commit 6f519e4

Browse files
committed
feat: add code to totp cli
1 parent fbc80b2 commit 6f519e4

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

main.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,37 @@ func generateTOTP(c *cli.Context) error {
3131
q, _ := url.ParseQuery(u.RawQuery)
3232
q.Add("secret", secret)
3333
u.RawQuery = q.Encode()
34-
fmt.Println("Nginx Variable:")
3534

36-
nginxVariable1 := fmt.Sprintf("set $protection_config_totp_secret '%s';", secret)
37-
fmt.Println("")
38-
fmt.Println(nginxVariable1)
35+
t1 := time.Now()
36+
passCode1, err := totp.GenerateCodeCustom(secret, t1, totp.ValidateOpts{
37+
Skew: 1,
38+
Digits: otp.DigitsSix,
39+
Algorithm: otp.AlgorithmSHA1,
40+
})
41+
42+
if err != nil {
43+
panic(err)
44+
}
45+
46+
t2 := time.Now().Add(time.Second * time.Duration(30))
47+
passCode2, err := totp.GenerateCodeCustom(secret, t2, totp.ValidateOpts{
48+
Skew: 1,
49+
Digits: otp.DigitsSix,
50+
Algorithm: otp.AlgorithmSHA1,
51+
})
52+
53+
if err != nil {
54+
panic(err)
55+
}
56+
57+
fmt.Println("Current password code:")
58+
fmt.Println(t1.Format("15:04:05 MST"))
59+
fmt.Println(passCode1)
60+
fmt.Println("Next password code:")
61+
fmt.Println(t2.Format("15:04:05 MST"))
62+
fmt.Println(passCode2)
3963
fmt.Println("")
64+
4065
fmt.Println("URI:")
4166
fmt.Println(u)
4267
fmt.Println("")

0 commit comments

Comments
 (0)