feat: print the expiration time of TOTP code
This commit is contained in:
parent
9361d471ef
commit
17dac7d440
4 changed files with 13 additions and 5 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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:
|
||||||
|
|
11
gpm/entry.go
11
gpm/entry.go
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue