Skip to content

Commit

Permalink
feat: add code to totp cli
Browse files Browse the repository at this point in the history
  • Loading branch information
mhf-ir committed Feb 2, 2023
1 parent fbc80b2 commit 6f519e4
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,37 @@ func generateTOTP(c *cli.Context) error {
q, _ := url.ParseQuery(u.RawQuery)
q.Add("secret", secret)
u.RawQuery = q.Encode()
fmt.Println("Nginx Variable:")

nginxVariable1 := fmt.Sprintf("set $protection_config_totp_secret '%s';", secret)
fmt.Println("")
fmt.Println(nginxVariable1)
t1 := time.Now()
passCode1, err := totp.GenerateCodeCustom(secret, t1, totp.ValidateOpts{
Skew: 1,
Digits: otp.DigitsSix,
Algorithm: otp.AlgorithmSHA1,
})

if err != nil {
panic(err)
}

t2 := time.Now().Add(time.Second * time.Duration(30))
passCode2, err := totp.GenerateCodeCustom(secret, t2, totp.ValidateOpts{
Skew: 1,
Digits: otp.DigitsSix,
Algorithm: otp.AlgorithmSHA1,
})

if err != nil {
panic(err)
}

fmt.Println("Current password code:")
fmt.Println(t1.Format("15:04:05 MST"))
fmt.Println(passCode1)
fmt.Println("Next password code:")
fmt.Println(t2.Format("15:04:05 MST"))
fmt.Println(passCode2)
fmt.Println("")

fmt.Println("URI:")
fmt.Println(u)
fmt.Println("")
Expand Down

0 comments on commit 6f519e4

Please sign in to comment.