Skip to content

Commit

Permalink
added demo function to example/main.go for GenerateCodeCustom (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvineetmenon committed May 11, 2020
1 parent 2257f83 commit d3764ec
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (

"bufio"
"bytes"
"encoding/base32"
"fmt"
"image/png"
"io/ioutil"
"os"
"time"
)

func display(key *otp.Key, data []byte) {
Expand All @@ -30,6 +32,22 @@ func promptForPasscode() string {
return text
}

// Demo function, not used in main
// Generates Passcode using a UTF-8 (not base32) secret and custom paramters
func GeneratePassCode(utf8string string) string{
secret := base32.StdEncoding.EncodeToString([]byte(utf8string))
passcode, err := totp.GenerateCodeCustom(secret, time.Now(), totp.ValidateOpts{
Period: 30,
Skew: 1,
Digits: otp.DigitsSix,
Algorithm: otp.AlgorithmSHA512,
})
if err != nil {
panic(err)
}
return passcode
}

func main() {
key, err := totp.Generate(totp.GenerateOpts{
Issuer: "Example.com",
Expand Down

0 comments on commit d3764ec

Please sign in to comment.