From 0b2bc83d82c99e1f4177048e91b6f53d4f664a3b Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Fri, 18 Mar 2022 19:12:02 +0100 Subject: [PATCH] Fix test again --- cmd/create-account/main.go | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/cmd/create-account/main.go b/cmd/create-account/main.go index 147581180..2719f8680 100644 --- a/cmd/create-account/main.go +++ b/cmd/create-account/main.go @@ -157,21 +157,24 @@ func getPassword(password, pwdFile string, pwdStdin bool, r io.Reader) (string, } // If no parameter was set, ask the user to provide the password - fmt.Print("Enter Password: ") - bytePassword, err := term.ReadPassword(int(os.Stdin.Fd())) - if err != nil { - return "", fmt.Errorf("Unable to read password: %v", err) + if password == "" { + fmt.Print("Enter Password: ") + bytePassword, err := term.ReadPassword(int(os.Stdin.Fd())) + if err != nil { + return "", fmt.Errorf("Unable to read password: %v", err) + } + fmt.Println() + fmt.Print("Confirm Password: ") + bytePassword2, err := term.ReadPassword(int(os.Stdin.Fd())) + if err != nil { + return "", fmt.Errorf("Unable to read password: %v", err) + } + fmt.Println() + if strings.TrimSpace(string(bytePassword)) != strings.TrimSpace(string(bytePassword2)) { + return "", fmt.Errorf("Entered passwords don't match") + } + return strings.TrimSpace(string(bytePassword)), nil } - fmt.Println() - fmt.Print("Confirm Password: ") - bytePassword2, err := term.ReadPassword(int(os.Stdin.Fd())) - if err != nil { - return "", fmt.Errorf("Unable to read password: %v", err) - } - fmt.Println() - if strings.TrimSpace(string(bytePassword)) != strings.TrimSpace(string(bytePassword2)) { - return "", fmt.Errorf("Entered passwords don't match") - } - return strings.TrimSpace(string(bytePassword)), nil + return password, nil }