mirror of
https://github.com/1f349/twofactor.git
synced 2024-12-22 07:24:12 +00:00
added method to get the secret out
This commit is contained in:
parent
70189459df
commit
92de2f4a0e
17
totp.go
17
totp.go
@ -12,16 +12,17 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/sec51/convert"
|
|
||||||
"github.com/sec51/convert/bigendian"
|
|
||||||
"github.com/sec51/cryptoengine"
|
|
||||||
qr "github.com/sec51/qrcode"
|
|
||||||
"hash"
|
"hash"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/sec51/convert"
|
||||||
|
"github.com/sec51/convert/bigendian"
|
||||||
|
"github.com/sec51/cryptoengine"
|
||||||
|
qr "github.com/sec51/qrcode"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -270,6 +271,14 @@ func calculateToken(counter []byte, digits int, h hash.Hash) string {
|
|||||||
return fmt.Sprintf(fmtStr, mod)
|
return fmt.Sprintf(fmtStr, mod)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Secret returns the underlying base32 encoded secret.
|
||||||
|
// This should only be displayed the first time a user enables 2FA,
|
||||||
|
// and should be transmitted over a secure connection.
|
||||||
|
// Useful for supporting TOTP clients that don't support QR scanning.
|
||||||
|
func (otp *Totp) Secret() string {
|
||||||
|
return base32.StdEncoding.EncodeToString(otp.key)
|
||||||
|
}
|
||||||
|
|
||||||
// URL returns a suitable URL, such as for the Google Authenticator app
|
// URL returns a suitable URL, such as for the Google Authenticator app
|
||||||
// example: otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example
|
// example: otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example
|
||||||
func (otp *Totp) url() (string, error) {
|
func (otp *Totp) url() (string, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user