mirror of
https://github.com/mitchell/selfpass.git
synced 2025-12-15 13:47:21 +00:00
Fix setting empty OTP secret; minor refactors
This commit is contained in:
parent
2096d6ada8
commit
e136b40b70
6 changed files with 33 additions and 30 deletions
|
|
@ -111,20 +111,23 @@ password.`,
|
|||
check(survey.AskOne(prompt, &otp, nil))
|
||||
|
||||
if otp {
|
||||
var copyOTP bool
|
||||
var secret string
|
||||
|
||||
prompt = &survey.Password{Message: "OTP secret:"}
|
||||
check(survey.AskOne(prompt, &secret, nil))
|
||||
|
||||
ciphersecret, err := crypto.CBCEncrypt(keypass, []byte(secret))
|
||||
check(err)
|
||||
if secret != "" {
|
||||
ciphersecret, err := crypto.CBCEncrypt(keypass, []byte(secret))
|
||||
check(err)
|
||||
|
||||
ci.OTPSecret = base64.StdEncoding.EncodeToString(ciphersecret)
|
||||
ci.OTPSecret = base64.StdEncoding.EncodeToString(ciphersecret)
|
||||
|
||||
var copyotp bool
|
||||
prompt = &survey.Confirm{Message: "Copy new OTP to clipboard?", Default: true}
|
||||
check(survey.AskOne(prompt, ©otp, nil))
|
||||
prompt = &survey.Confirm{Message: "Copy new OTP to clipboard?", Default: true}
|
||||
check(survey.AskOne(prompt, ©OTP, nil))
|
||||
}
|
||||
|
||||
if copyotp {
|
||||
if copyOTP {
|
||||
otp, err := totp.GenerateCode(secret, time.Now())
|
||||
check(err)
|
||||
|
||||
|
|
@ -132,9 +135,9 @@ password.`,
|
|||
fmt.Println("Wrote one time password to clipboard.")
|
||||
|
||||
prompt = &survey.Confirm{Message: "Anotha one?", Default: true}
|
||||
check(survey.AskOne(prompt, ©otp, nil))
|
||||
check(survey.AskOne(prompt, ©OTP, nil))
|
||||
|
||||
if copyotp {
|
||||
if copyOTP {
|
||||
otp, err := totp.GenerateCode(secret, time.Now().Add(time.Second*30))
|
||||
check(err)
|
||||
|
||||
|
|
|
|||
|
|
@ -145,20 +145,25 @@ password.`,
|
|||
check(survey.AskOne(prompt, &otp, nil))
|
||||
|
||||
if otp {
|
||||
var copyOTP bool
|
||||
var secret string
|
||||
|
||||
ci.OTPSecret = ""
|
||||
|
||||
prompt = &survey.Password{Message: "OTP secret:"}
|
||||
check(survey.AskOne(prompt, &secret, nil))
|
||||
|
||||
ciphersecret, err := crypto.CBCEncrypt(keypass, []byte(secret))
|
||||
check(err)
|
||||
if secret != "" {
|
||||
ciphersecret, err := crypto.CBCEncrypt(keypass, []byte(secret))
|
||||
check(err)
|
||||
|
||||
ci.OTPSecret = base64.StdEncoding.EncodeToString(ciphersecret)
|
||||
ci.OTPSecret = base64.StdEncoding.EncodeToString(ciphersecret)
|
||||
|
||||
var copyotp bool
|
||||
prompt = &survey.Confirm{Message: "Copy new OTP to clipboard?", Default: true}
|
||||
check(survey.AskOne(prompt, ©otp, nil))
|
||||
prompt = &survey.Confirm{Message: "Copy new OTP to clipboard?", Default: true}
|
||||
check(survey.AskOne(prompt, ©OTP, nil))
|
||||
}
|
||||
|
||||
if copyotp {
|
||||
if copyOTP {
|
||||
otp, err := totp.GenerateCode(secret, time.Now())
|
||||
check(err)
|
||||
|
||||
|
|
@ -166,9 +171,9 @@ password.`,
|
|||
fmt.Println("Wrote one time password to clipboard.")
|
||||
|
||||
prompt = &survey.Confirm{Message: "Anotha one?", Default: true}
|
||||
check(survey.AskOne(prompt, ©otp, nil))
|
||||
check(survey.AskOne(prompt, ©OTP, nil))
|
||||
|
||||
if copyotp {
|
||||
if copyOTP {
|
||||
otp, err := totp.GenerateCode(secret, time.Now().Add(time.Second*30))
|
||||
check(err)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue