fix: retry password-prompt if 2nd entry doesn't match the 1st (#203)

This commit is contained in:
Daniel Moran 2021-07-21 12:23:39 -04:00 committed by GitHub
parent 68cfff003a
commit a111d83b5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -87,19 +87,23 @@ func (t *terminalStdio) GetSecret(prompt string, minLen int) (password string, e
// GetPassword prompts the user for a secret twice, and inputs must match.
// Uses stdio.MinPasswordLen as the minimum input length
func (t *terminalStdio) GetPassword(prompt string) (string, error) {
pass1, err := t.GetSecret(prompt, MinPasswordLen)
if err != nil {
return "", err
for {
pass1, err := t.GetSecret(prompt, MinPasswordLen)
if err != nil {
return "", err
}
// Don't bother with the length check the 2nd time, since we check equality to pass1.
pass2, err := t.GetSecret(prompt+" again", 0)
if err != nil {
return "", err
}
if pass1 == pass2 {
return pass1, nil
}
if err := t.Error("Passwords do not match"); err != nil {
return "", err
}
}
// Don't bother with the length check the 2nd time, since we check equality to pass1.
pass2, err := t.GetSecret(prompt+" again", 0)
if err != nil {
return "", err
}
if pass1 == pass2 {
return pass1, nil
}
return "", t.Error("Passwords do not match")
}
// GetConfirm asks the user for a y/n answer to a prompt.