Fix setting empty OTP secret; minor refactors

This commit is contained in:
Mitchell Simon 2019-09-07 01:44:43 -04:00
parent 2096d6ada8
commit e136b40b70
6 changed files with 33 additions and 30 deletions

View file

@ -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, &copyotp, nil))
prompt = &survey.Confirm{Message: "Copy new OTP to clipboard?", Default: true}
check(survey.AskOne(prompt, &copyOTP, 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, &copyotp, nil))
check(survey.AskOne(prompt, &copyOTP, nil))
if copyotp {
if copyOTP {
otp, err := totp.GenerateCode(secret, time.Now().Add(time.Second*30))
check(err)

View file

@ -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, &copyotp, nil))
prompt = &survey.Confirm{Message: "Copy new OTP to clipboard?", Default: true}
check(survey.AskOne(prompt, &copyOTP, 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, &copyotp, nil))
check(survey.AskOne(prompt, &copyOTP, nil))
if copyotp {
if copyOTP {
otp, err := totp.GenerateCode(secret, time.Now().Add(time.Second*30))
check(err)