From b8a3c39984c7572c984159c980b22ced83a14c9b Mon Sep 17 00:00:00 2001 From: James Shubin Date: Fri, 22 Mar 2024 00:12:57 -0400 Subject: [PATCH] util: password: Add a new helper util function for passwords Also fix some doc issues from an earlier copy paste. --- util/password/password.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/util/password/password.go b/util/password/password.go index 24594a4c..0559653e 100644 --- a/util/password/password.go +++ b/util/password/password.go @@ -66,12 +66,20 @@ func ReadPassword() ([]byte, error) { // ReadPasswordCtx reads a password from stdin and returns the result. It hides // the display of the password typed. It cancels reading when the context // closes. For more options try ReadPasswordCtxFdPrompt instead. If interrupted -// by an uncaught signal during read, then this can bork your terminal. It's -// best to use a version with a context instead. +// by an uncaught signal during read, then this can bork your terminal. func ReadPasswordCtx(ctx context.Context) ([]byte, error) { 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 // 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