Skip to content

Commit

Permalink
fix: hide sensitive input
Browse files Browse the repository at this point in the history
Fixes #28 by using Go's x/term package's ReadPassword
  • Loading branch information
aripalo committed May 12, 2022
1 parent 9ee92c0 commit af886e5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/msg/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func Error(prefix emoji.Emoji, message string) {
}

func Prompt(prefix emoji.Emoji, message string) {
d.Promptln(prefix, message)
d.Prompt(prefix, message)
}

func Fatal(message string) {
Expand Down
9 changes: 4 additions & 5 deletions internal/prompt/prompt.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package prompt

import (
"bufio"
"context"
"os"
"strings"
"syscall"

"github.com/ncruces/zenity"
"golang.org/x/term"
)

func Password(ctx context.Context, title string, text string) (string, error) {
Expand Down Expand Up @@ -37,12 +37,11 @@ func Dialog(ctx context.Context, title string, text string) (string, error) {
}

func Cli(ctx context.Context, text string) (string, error) {
reader := bufio.NewReader(os.Stdin)

value, err := reader.ReadString('\n')
value, err := term.ReadPassword(int(syscall.Stdin))
if err != nil {
return "", err
}

return strings.TrimSpace(value), nil
return strings.TrimSpace(string(value)), nil
}

0 comments on commit af886e5

Please sign in to comment.