Added a command to change a user's password
This commit is contained in:
35
lib/cli/cli.go
Normal file
35
lib/cli/cli.go
Normal file
@ -0,0 +1,35 @@
|
||||
package lib
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// prompt user for input
|
||||
func GetUserInput(consoleMsg string, confirm bool) (string, error) {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
fmt.Print(fmt.Sprintf("%s: ", consoleMsg))
|
||||
input, err := reader.ReadString('\n')
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if confirm {
|
||||
fmt.Print("Confirm: ")
|
||||
confirm_input, confirm_err := reader.ReadString('\n')
|
||||
|
||||
if confirm_err != nil {
|
||||
return "", confirm_err
|
||||
}
|
||||
|
||||
if input != confirm_input {
|
||||
return "", errors.New("The passwords provided do not match!")
|
||||
}
|
||||
}
|
||||
|
||||
return strings.TrimSpace(input), nil
|
||||
}
|
Reference in New Issue
Block a user