Use stderr for password prompt

Fixes #12
This commit is contained in:
Jannis Mattheis
2020-10-09 13:46:37 +00:00
parent 4c849059ba
commit a02e885370
+6 -2
View File
@@ -2,9 +2,12 @@ package cmd
import (
"fmt"
"os"
"syscall"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/screego/server/logger"
"github.com/urfave/cli"
"golang.org/x/crypto/bcrypt"
"golang.org/x/crypto/ssh/terminal"
@@ -17,6 +20,7 @@ var hashCmd = cli.Command{
&cli.StringFlag{Name: "pass"},
},
Action: func(ctx *cli.Context) {
logger.Init(zerolog.ErrorLevel)
name := ctx.String("name")
pass := []byte(ctx.String("pass"))
if name == "" {
@@ -25,12 +29,12 @@ var hashCmd = cli.Command{
if len(pass) == 0 {
var err error
fmt.Print("Enter Password: ")
_, _ = fmt.Fprint(os.Stderr, "Enter Password: ")
pass, err = terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
log.Fatal().Err(err).Msg("could not read stdin")
}
fmt.Println("")
_, _ = fmt.Fprintln(os.Stderr, "")
}
hashedPw, err := bcrypt.GenerateFromPassword(pass, 12)
if err != nil {