summaryrefslogtreecommitdiff
path: root/password.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-06-05 14:26:16 +0200
committerJakob Unterwurzacher2016-06-05 14:32:07 +0200
commit0c80cca674931c9dbfc69c25df24d53abbdd63a9 (patch)
treec11cae555954fc08f3e28f22b6ed23ea5717a083 /password.go
parentca54b665e32a9b298ea3e70b5da0108db3a71364 (diff)
toggledlog: convert remaing naked fmt.Print*
Several fatal errors were just printed to stdout, which meant they were invisible when running the test suite. Fix this by introducing toggledlog.Fatal and convert as follows: Fatal errors -> toggledlog.Fatal Warnings -> toggledlog.Warn Password prompts -> fmt.Fprintf
Diffstat (limited to 'password.go')
-rw-r--r--password.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/password.go b/password.go
index 935ff87..01c71a7 100644
--- a/password.go
+++ b/password.go
@@ -7,16 +7,18 @@ import (
"strings"
"golang.org/x/crypto/ssh/terminal"
+
+ "github.com/rfjakob/gocryptfs/internal/toggledlog"
)
func readPasswordTwice(extpass string) string {
if extpass == "" {
- fmt.Printf("Password: ")
+ fmt.Fprintf(os.Stderr, "Password: ")
p1 := readPassword("")
- fmt.Printf("Repeat: ")
+ fmt.Fprintf(os.Stderr, "Repeat: ")
p2 := readPassword("")
if p1 != p2 {
- fmt.Println(colorRed + "Passwords do not match" + colorReset)
+ toggledlog.Fatal.Println(colorRed + "Passwords do not match" + colorReset)
os.Exit(ERREXIT_PASSWORD)
}
return p1
@@ -37,7 +39,7 @@ func readPassword(extpass string) string {
cmd.Stderr = os.Stderr
output, err = cmd.Output()
if err != nil {
- fmt.Printf(colorRed+"extpass program returned error: %v\n"+colorReset, err)
+ toggledlog.Fatal.Printf(colorRed+"extpass program returned error: %v\n"+colorReset, err)
os.Exit(ERREXIT_PASSWORD)
}
// Trim trailing newline like terminal.ReadPassword() does
@@ -48,14 +50,14 @@ func readPassword(extpass string) string {
fd := int(os.Stdin.Fd())
output, err = terminal.ReadPassword(fd)
if err != nil {
- fmt.Printf(colorRed+"Could not read password from terminal: %v\n"+colorReset, err)
+ toggledlog.Fatal.Printf(colorRed+"Could not read password from terminal: %v\n"+colorReset, err)
os.Exit(ERREXIT_PASSWORD)
}
- fmt.Printf("\n")
+ fmt.Fprintf(os.Stderr, "\n")
}
password = string(output)
if password == "" {
- fmt.Printf(colorRed + "Password is empty\n" + colorReset)
+ toggledlog.Fatal.Printf(colorRed + "Password is empty\n" + colorReset)
os.Exit(ERREXIT_PASSWORD)
}
return password