From 6b59ccea527d4bd0c707acb3155b20c082c9caa3 Mon Sep 17 00:00:00 2001 From: Dan Mills Date: Fri, 3 Mar 2023 15:42:34 -0800 Subject: [PATCH] Add error checking on inpurt string --- main.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main.go b/main.go index c569eb7..37c6ef4 100644 --- a/main.go +++ b/main.go @@ -1,8 +1,10 @@ package main import ( + "encoding/base32" "fmt" "os" + "strings" "time" "github.com/pquerna/otp/totp" @@ -12,6 +14,13 @@ func main() { // All we care about is the last argument which is the secret a := os.Args s := a[len(a)-1] + s = strings.ToUpper(s) + + _, err := base32.StdEncoding.DecodeString(s) + if err != nil { + fmt.Println("You must specify a valid base32 string") + os.Exit(1) + } // Generate and return the code c, err := totp.GenerateCode(s, time.Now())