MCPcopy Index your code
hub / github.com/kopia/kopia / askPass

Function askPass

cli/password.go:97–121  ·  view source on GitHub ↗

askPass presents a given prompt and asks the user for password.

(out io.Writer, prompt string)

Source from the content-addressed store, hash-verified

95
96// askPass presents a given prompt and asks the user for password.
97func askPass(out io.Writer, prompt string) (string, error) {
98 fd, err := intFd(os.Stdin)
99 if err != nil {
100 return "", errors.Wrap(err, "password input error")
101 }
102
103 for range 5 {
104 fmt.Fprint(out, prompt) //nolint:errcheck
105
106 passBytes, err := term.ReadPassword(fd)
107 if err != nil {
108 return "", errors.Wrap(err, "password prompt error")
109 }
110
111 fmt.Fprintln(out) //nolint:errcheck
112
113 if len(passBytes) == 0 {
114 continue
115 }
116
117 return string(passBytes), nil
118 }
119
120 return "", errors.New("can't get password")
121}
122
123var errFdConversionOverflows = errors.New("uintptr file descriptor conversion to int overflows")
124

Callers 5

askConfirmPassFunction · 0.85
ConnectMethod · 0.85

Calls 1

intFdFunction · 0.85

Tested by

no test coverage detected