aboutsummaryrefslogtreecommitdiff
path: root/gocryptfs_main/password.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-10-07 21:26:17 +0200
committerJakob Unterwurzacher2015-10-07 21:26:17 +0200
commit65ba0739d5de756a437e0f840649583fa835a560 (patch)
tree09ada31a5e752d9e00a3f2424b8a53d2bc59bb0c /gocryptfs_main/password.go
parent03502861ce9aaf3606b37b999d19ac25ccfbf06b (diff)
Implement "gocryptfs --passwd" (pasword changing)
Diffstat (limited to 'gocryptfs_main/password.go')
-rw-r--r--gocryptfs_main/password.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/gocryptfs_main/password.go b/gocryptfs_main/password.go
new file mode 100644
index 0000000..821ecb4
--- /dev/null
+++ b/gocryptfs_main/password.go
@@ -0,0 +1,31 @@
+package main
+
+import (
+ "fmt"
+ "golang.org/x/crypto/ssh/terminal"
+ "os"
+)
+
+func readPasswordTwice() string {
+ fmt.Printf("Password: ")
+ p1 := readPassword()
+ fmt.Printf("\nRepeat: ")
+ p2 := readPassword()
+ fmt.Printf("\n")
+ if p1 != p2 {
+ fmt.Printf("Passwords do not match\n")
+ os.Exit(ERREXIT_PASSWORD)
+ }
+ return p1
+}
+
+// Get password from terminal
+func readPassword() string {
+ fd := int(os.Stdin.Fd())
+ p, err := terminal.ReadPassword(fd)
+ if err != nil {
+ fmt.Printf("Error: Could not read password: %v\n", err)
+ os.Exit(ERREXIT_PASSWORD)
+ }
+ return string(p)
+}