@@ -131,26 +131,29 @@ func login() *cobra.Command {
131
131
}
132
132
133
133
if password == "" {
134
- password , err = cliui .Prompt (cmd , cliui.PromptOptions {
135
- Text : "Enter a " + cliui .Styles .Field .Render ("password" ) + ":" ,
136
- Secret : true ,
137
- Validate : cliui .ValidateNotEmpty ,
138
- })
139
- if err != nil {
140
- return xerrors .Errorf ("specify password prompt: %w" , err )
141
- }
142
- _ , err = cliui .Prompt (cmd , cliui.PromptOptions {
143
- Text : "Confirm " + cliui .Styles .Field .Render ("password" ) + ":" ,
144
- Secret : true ,
145
- Validate : func (s string ) error {
146
- if s != password {
147
- return xerrors .Errorf ("Passwords do not match" )
148
- }
149
- return nil
150
- },
151
- })
152
- if err != nil {
153
- return xerrors .Errorf ("confirm password prompt: %w" , err )
134
+ var matching bool
135
+
136
+ for ! matching {
137
+ password , err = cliui .Prompt (cmd , cliui.PromptOptions {
138
+ Text : "Enter a " + cliui .Styles .Field .Render ("password" ) + ":" ,
139
+ Secret : true ,
140
+ Validate : cliui .ValidateNotEmpty ,
141
+ })
142
+ if err != nil {
143
+ return xerrors .Errorf ("specify password prompt: %w" , err )
144
+ }
145
+ confirm , err := cliui .Prompt (cmd , cliui.PromptOptions {
146
+ Text : "Confirm " + cliui .Styles .Field .Render ("password" ) + ":" ,
147
+ Secret : true ,
148
+ })
149
+ if err != nil {
150
+ return xerrors .Errorf ("confirm password prompt: %w" , err )
151
+ }
152
+
153
+ matching = confirm == password
154
+ if ! matching {
155
+ _ , _ = fmt .Fprintln (cmd .OutOrStdout (), cliui .Styles .Error .Render ("Passwords do not match" ))
156
+ }
154
157
}
155
158
}
156
159
0 commit comments