Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from evilhamsterman/testing
Browse files Browse the repository at this point in the history
Add error checking on input string
  • Loading branch information
evilhamsterman authored Mar 21, 2023
2 parents 81a6227 + 6b59cce commit 09492cc
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package main

import (
"encoding/base32"
"fmt"
"os"
"strings"
"time"

"github.com/pquerna/otp/totp"
Expand All @@ -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())
Expand Down

0 comments on commit 09492cc

Please # to comment.