feat: print the expiration time of TOTP code

This commit is contained in:
Adrien Waksberg 2019-07-20 15:45:22 +02:00
parent 9361d471ef
commit 17dac7d440
4 changed files with 13 additions and 5 deletions

View file

@ -11,6 +11,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
- Use go module to get this software - Use go module to get this software
- Generate random password - Generate random password
- Print the expiration time of TOTP code
## v1.0.0 - 2019-07-12 ## v1.0.0 - 2019-07-12

View file

@ -7,7 +7,7 @@ gpm is passwords manager write in go and use AES-256 to encrypt the wallets
## Features ## Features
- generate OTP code - generate TOTP code
- copy your login, password or otp in clipboard - copy your login, password or otp in clipboard
- manage multiple wallets - manage multiple wallets
- generate random password - generate random password

View file

@ -267,7 +267,9 @@ func (c *Cli) copyEntry() {
case "p": case "p":
clipboard.WriteAll(entry.Password) clipboard.WriteAll(entry.Password)
case "o": case "o":
clipboard.WriteAll(entry.OTPCode()) code, time, _ := entry.OTPCode()
fmt.Printf("this OTP code is available for %d seconds\n", time)
clipboard.WriteAll(code)
case "q": case "q":
os.Exit(0) os.Exit(0)
default: default:

View file

@ -58,7 +58,12 @@ func (e *Entry) GenerateID() {
} }
// OTPCode generate an OTP Code // OTPCode generate an OTP Code
func (e *Entry) OTPCode() string { func (e *Entry) OTPCode() (string, int64, error){
code, _ := totp.GenerateCode(e.OTP, time.Now()) code, err := totp.GenerateCode(e.OTP, time.Now())
return code time := 30 - (time.Now().Unix() % 30)
if err != nil {
return "", 0, err
}
return code, time, nil
} }