Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added demo function to example/main.go for GenerateCodeCustom #53

Merged
merged 1 commit into from
May 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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