libgocryptfs/password.go
Jakob Unterwurzacher 5dc7e44aa2 Move main files to top level dir
This is in preparation of getting rid of the shell wrapper
2015-10-11 17:14:18 +02:00

32 lines
572 B
Go

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)
}