diff --git a/CHANGELOG.md b/CHANGELOG.md index 235f5ea..94e8092 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/) - Use go module to get this software - Generate random password +- Print the expiration time of TOTP code ## v1.0.0 - 2019-07-12 diff --git a/README.md b/README.md index 3a266a7..0965124 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ gpm is passwords manager write in go and use AES-256 to encrypt the wallets ## Features -- generate OTP code +- generate TOTP code - copy your login, password or otp in clipboard - manage multiple wallets - generate random password diff --git a/gpm/cli.go b/gpm/cli.go index 2f8f51d..25259a5 100644 --- a/gpm/cli.go +++ b/gpm/cli.go @@ -267,7 +267,9 @@ func (c *Cli) copyEntry() { case "p": clipboard.WriteAll(entry.Password) 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": os.Exit(0) default: diff --git a/gpm/entry.go b/gpm/entry.go index 77436dc..410a41b 100644 --- a/gpm/entry.go +++ b/gpm/entry.go @@ -58,7 +58,12 @@ func (e *Entry) GenerateID() { } // OTPCode generate an OTP Code -func (e *Entry) OTPCode() string { - code, _ := totp.GenerateCode(e.OTP, time.Now()) - return code +func (e *Entry) OTPCode() (string, int64, error){ + code, err := totp.GenerateCode(e.OTP, time.Now()) + time := 30 - (time.Now().Unix() % 30) + if err != nil { + return "", 0, err + } + + return code, time, nil }