mirror of
https://github.com/Forceu/Gokapi.git
synced 2026-05-03 21:10:50 -05:00
Fixed password CLI input on Windows
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user