forked from oleiade/trousseau
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli_helpers.go
51 lines (41 loc) · 1.02 KB
/
cli_helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package trousseau
import (
"fmt"
"os"
"github.com/howeyc/gopass"
)
const passPhraseMsg string = "Passphrase: "
const confirmMsg string = "Confirm Passphrase: "
const errorMsg string = "Passphrase error occurred. Exiting..."
// PromptForHiddenInput will prompt on stdin with the provided
// message and will hide the user input. This is intended to be used
// to ask the user for password or passphrase
func PromptForHiddenInput(msg string) string {
fmt.Printf(msg)
pass, _ := gopass.GetPasswd()
return string(pass)
}
func PromptForHiddenInputConfirm() string {
i := 0
for {
if i >= 3 {
fmt.Println(errorMsg)
os.Exit(1)
}
fmt.Printf(passPhraseMsg)
inputPass, _ := gopass.GetPasswd()
if string(inputPass) == "" {
fmt.Printf("Empty passphrase not allowed\n\n")
i++
continue
}
fmt.Printf(confirmMsg)
confirmPass, _ := gopass.GetPasswd()
if string(inputPass) == string(confirmPass) {
return string(inputPass)
} else {
fmt.Printf("Passphrases did not match. Please try again\n\n")
}
i++
}
}