Fixed password CLI input on Windows

This commit is contained in:
Marc Ole Bulling
2021-05-11 15:17:56 +02:00
parent 84c6a07635
commit f965aa9807
2 changed files with 14 additions and 14 deletions
+2 -14
View File
@@ -12,9 +12,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"golang.org/x/term"
"os"
"runtime"
"strconv"
"strings"
"sync"
@@ -234,13 +232,13 @@ func askForPassword() string {
}
return envPassword
}
password1 := readPassword()
password1 := helper.ReadPassword()
if utf8.RuneCountInString(password1) < minLengthPassword {
fmt.Println("\nPassword needs to be at least " + strconv.Itoa(minLengthPassword) + " characters long")
return askForPassword()
}
fmt.Print("\nPassword (repeat): ")
password2 := readPassword()
password2 := helper.ReadPassword()
if password1 != password2 {
fmt.Println("\nPasswords dont match")
return askForPassword()
@@ -249,16 +247,6 @@ func askForPassword() string {
return password1
}
func readPassword() string {
if runtime.GOOS != "windows" {
pw, err := term.ReadPassword(0)
if err == nil {
return string(pw)
}
}
return helper.ReadLine()
}
// Asks if the server shall be bound to 127.0.0.1 or loads it from env and returns result as bool
// Always returns environment.IsFalse for Docker environment
func askForLocalOnly() string {
+12
View File
@@ -6,7 +6,9 @@ Simplified OS functions
import (
"bufio"
"golang.org/x/term"
"os"
"syscall"
)
// FolderExists returns true if a folder exists
@@ -43,6 +45,16 @@ func ReadLine() string {
return text
}
// ReadPassword reads a line without displaying input from the terminal and returns it as a string
func ReadPassword() string {
// int conversion is required for Windows systems
pw, err := term.ReadPassword(int(syscall.Stdin))
if err == nil {
return string(pw)
}
return ReadLine()
}
// Check panics if error is not nil
func Check(e error) {
if e != nil {