1
0
Fork 0
mirror of https://github.com/Luzifer/vault-otp-ui.git synced 2024-11-08 08:10:11 +00:00

Allow other digit counts than 6 or 8

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-09-14 13:31:45 +02:00
parent a0e9798345
commit e521ab10a1
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
3 changed files with 11 additions and 2 deletions

1
go.mod
View file

@ -15,6 +15,7 @@ require (
github.com/onsi/ginkgo v1.10.1 // indirect
github.com/onsi/gomega v1.7.0 // indirect
github.com/pierrec/lz4 v2.3.0+incompatible // indirect
github.com/pkg/errors v0.8.1
github.com/pquerna/otp v1.2.0
github.com/sirupsen/logrus v1.4.2
github.com/tdewolff/minify v2.3.6+incompatible

2
go.sum
View file

@ -105,6 +105,8 @@ github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pierrec/lz4 v2.3.0+incompatible h1:CZzRn4Ut9GbUkHlQ7jqBXeZQV41ZSKWFc302ZU6lUTk=
github.com/pierrec/lz4 v2.3.0+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=

View file

@ -4,11 +4,13 @@ import (
"fmt"
"path"
"sort"
"strconv"
"strings"
"sync"
"time"
"github.com/hashicorp/vault/api"
"github.com/pkg/errors"
"github.com/pquerna/otp"
"github.com/pquerna/otp/totp"
log "github.com/sirupsen/logrus"
@ -36,8 +38,12 @@ func (t *token) GenerateCode(in time.Time) error {
Algorithm: otp.AlgorithmSHA1,
}
if t.Digits == "8" {
opts.Digits = otp.DigitsEight
if t.Digits != "" {
d, err := strconv.Atoi(t.Digits)
if err != nil {
return errors.Wrap(err, "Unable to parse digits to int")
}
opts.Digits = otp.Digits(d)
}
var err error