style: generate the otp code in entry struct
This commit is contained in:
parent
0e80f704bc
commit
9361d471ef
2 changed files with 9 additions and 3 deletions
|
@ -24,7 +24,6 @@ import(
|
|||
"time"
|
||||
"github.com/atotto/clipboard"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/pquerna/otp/totp"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
)
|
||||
|
||||
|
@ -268,8 +267,7 @@ func (c *Cli) copyEntry() {
|
|||
case "p":
|
||||
clipboard.WriteAll(entry.Password)
|
||||
case "o":
|
||||
code, _ := totp.GenerateCode(entry.OTP, time.Now())
|
||||
clipboard.WriteAll(code)
|
||||
clipboard.WriteAll(entry.OTPCode())
|
||||
case "q":
|
||||
os.Exit(0)
|
||||
default:
|
||||
|
|
|
@ -18,6 +18,8 @@ import(
|
|||
"fmt"
|
||||
"time"
|
||||
"net/url"
|
||||
|
||||
"github.com/pquerna/otp/totp"
|
||||
)
|
||||
|
||||
// Entry struct have the password informations
|
||||
|
@ -54,3 +56,9 @@ func (e *Entry) Verify() error {
|
|||
func (e *Entry) GenerateID() {
|
||||
e.ID = fmt.Sprintf("%d", time.Now().UnixNano())
|
||||
}
|
||||
|
||||
// OTPCode generate an OTP Code
|
||||
func (e *Entry) OTPCode() string {
|
||||
code, _ := totp.GenerateCode(e.OTP, time.Now())
|
||||
return code
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue