util: password: Add a new helper util function for passwords
Also fix some doc issues from an earlier copy paste.
This commit is contained in:
@@ -66,12 +66,20 @@ func ReadPassword() ([]byte, error) {
|
|||||||
// ReadPasswordCtx reads a password from stdin and returns the result. It hides
|
// ReadPasswordCtx reads a password from stdin and returns the result. It hides
|
||||||
// the display of the password typed. It cancels reading when the context
|
// the display of the password typed. It cancels reading when the context
|
||||||
// closes. For more options try ReadPasswordCtxFdPrompt instead. If interrupted
|
// closes. For more options try ReadPasswordCtxFdPrompt instead. If interrupted
|
||||||
// by an uncaught signal during read, then this can bork your terminal. It's
|
// by an uncaught signal during read, then this can bork your terminal.
|
||||||
// best to use a version with a context instead.
|
|
||||||
func ReadPasswordCtx(ctx context.Context) ([]byte, error) {
|
func ReadPasswordCtx(ctx context.Context) ([]byte, error) {
|
||||||
return ReadPasswordCtxFdPrompt(ctx, int(os.Stdin.Fd()), StdPrompt)
|
return ReadPasswordCtxFdPrompt(ctx, int(os.Stdin.Fd()), StdPrompt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadPasswordCtxPrompt reads a password stdin and returns the result. It hides
|
||||||
|
// the display of the password typed. It cancels reading when the context
|
||||||
|
// closes. If specified, it will prompt the user with the prompt message. If
|
||||||
|
// interrupted by an uncaught signal during read, then this can bork your
|
||||||
|
// terminal.
|
||||||
|
func ReadPasswordCtxPrompt(ctx context.Context, prompt string) ([]byte, error) {
|
||||||
|
return ReadPasswordCtxFdPrompt(ctx, int(os.Stdin.Fd()), prompt)
|
||||||
|
}
|
||||||
|
|
||||||
// ReadPasswordCtxFdPrompt reads a password from the file descriptor and returns
|
// ReadPasswordCtxFdPrompt reads a password from the file descriptor and returns
|
||||||
// the result. It hides the display of the password typed. It cancels reading
|
// the result. It hides the display of the password typed. It cancels reading
|
||||||
// when the context closes. If specified, it will prompt the user with the
|
// when the context closes. If specified, it will prompt the user with the
|
||||||
|
|||||||
Reference in New Issue
Block a user