Skip to content

Commit

Permalink
hide passwd input
Browse files Browse the repository at this point in the history
  • Loading branch information
blacam committed Apr 6, 2020
1 parent 3b1ab7e commit 299ad04
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ POSSIBILITY OF SUCH DAMAGE.
*/

import (
"bufio"
"fmt"
"os"
"strings"
"syscall"

log "github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh/terminal"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -141,13 +141,15 @@ func passwordPrompt() {
// password _can_ be saved to the config file; however, prompt by default.
// consider this a hidden feature as passowrds should not be stored in in plain text.
if viper.Get("api.password") == nil {
r := bufio.NewReader(os.Stdin)
fmt.Printf("provide password for %s: ", viper.Get("api.username"))
p, err := r.ReadString('\n')

p, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
log.Fatal(err)
}
p = strings.TrimSpace(p)

viper.Set("api.password", p)

fmt.Println("")
}
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ require (
github.com/sirupsen/logrus v1.2.0
github.com/spf13/cobra v0.0.7
github.com/spf13/viper v1.6.2
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
)

0 comments on commit 299ad04

Please sign in to comment.