Browse Source

when entering/generating the password it's helpful to at least be asked to confirm the input so if you get something like an extraneous character, on confirmation, you could catch that

tags/v0.11.0-beta
Sean Enck 6 years ago
parent
commit
dcf4cb7cde
No account linked to committer's email address
1 changed files with 16 additions and 5 deletions
  1. 16
    5
      oragono.go

+ 16
- 5
oragono.go View File

@@ -24,6 +24,15 @@ import (
24 24
 
25 25
 var commit = ""
26 26
 
27
+// get a password from stdin from the user
28
+func getPassword() string {
29
+	bytePassword, err := terminal.ReadPassword(int(syscall.Stdin))
30
+	if err != nil {
31
+		log.Fatal("Error reading password:", err.Error())
32
+	}
33
+	return string(bytePassword)
34
+}
35
+
27 36
 func main() {
28 37
 	version := irc.SemVer
29 38
 	usage := `oragono.
@@ -56,16 +65,18 @@ Options:
56 65
 
57 66
 	if arguments["genpasswd"].(bool) {
58 67
 		fmt.Print("Enter Password: ")
59
-		bytePassword, err := terminal.ReadPassword(int(syscall.Stdin))
60
-		if err != nil {
61
-			log.Fatal("Error reading password:", err.Error())
68
+		password := getPassword()
69
+		fmt.Print("\n")
70
+		fmt.Print("Reenter Password: ")
71
+		confirm := getPassword()
72
+		fmt.Print("\n")
73
+		if confirm != password {
74
+			log.Fatal("passwords do not match")
62 75
 		}
63
-		password := string(bytePassword)
64 76
 		encoded, err := passwd.GenerateEncodedPassword(password)
65 77
 		if err != nil {
66 78
 			log.Fatal("encoding error:", err.Error())
67 79
 		}
68
-		fmt.Print("\n")
69 80
 		fmt.Println(encoded)
70 81
 	} else if arguments["initdb"].(bool) {
71 82
 		irc.InitDB(config.Datastore.Path)

Loading…
Cancel
Save