Skip to content

Commit

Permalink
extract askForPassword
Browse files Browse the repository at this point in the history
  • Loading branch information
mikew committed Oct 21, 2024
1 parent bc19c09 commit 656f15d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,7 @@ func getSshClientForServer(endpoint *Endpoint) (*ssh.Client, error) {
}))

authMethods = append(authMethods, ssh.PasswordCallback(func() (string, error) {
fmt.Printf("Password for %s: ", endpoint)
password, err := term.ReadPassword(0)
fmt.Println()
password, err := askForPassword(fmt.Sprintf("Password for %s: ", endpoint))
if err != nil {
slog.Error("Error reading password", "err", err)
return "", err
Expand Down Expand Up @@ -572,3 +570,15 @@ func parseServerString(server string) (*Endpoint, error) {
Port: finalPort,
}, nil
}

func askForPassword(message string) ([]byte, error) {
fmt.Print(message)
password, err := term.ReadPassword(0)
fmt.Println()

if err != nil {
return nil, err
}

return password, nil
}

0 comments on commit 656f15d

Please sign in to comment.