pash: Added password confirm to input
This commit is contained in:
parent
605faef0f0
commit
ea304bf2fa
32
pash
32
pash
|
@ -19,16 +19,15 @@ pw_add() {
|
|||
dd ibs=1 obs=1 count="${PASH_LENGTH:-50}" 2>/dev/null)
|
||||
|
||||
else
|
||||
printf 'Enter password: '
|
||||
# 'sread()' is a simple wrapper function around 'read'
|
||||
# to prevent user input from being printed to the terminal.
|
||||
sread pass "Enter password"
|
||||
sread pass2 "Enter password (again)"
|
||||
|
||||
# Disable terminal printing while the user inputs their
|
||||
# password. POSIX 'read' has no '-s' flag which would
|
||||
# effectively do the same thing.
|
||||
stty -echo
|
||||
read -r pass
|
||||
stty echo
|
||||
|
||||
printf '\n'
|
||||
# Disable this check as we dynamically populate the two
|
||||
# passwords using the 'sread()' function.
|
||||
# shellcheck disable=2154
|
||||
[ "$pass" = "$pass2" ] || die "Passwords do not match"
|
||||
fi
|
||||
|
||||
[ "$pass" ] || die "Failed to generate a password"
|
||||
|
@ -120,6 +119,21 @@ yn() {
|
|||
glob "$answer" '[yY]'
|
||||
}
|
||||
|
||||
sread() {
|
||||
# This is a simple wrapper around POSIX 'read' to print
|
||||
# a prompt and disable printing of user input.
|
||||
printf '%s: ' "$2"
|
||||
|
||||
# Disable terminal printing while the user inputs their
|
||||
# password. POSIX 'read' has no '-s' flag which would
|
||||
# effectively do the same thing.
|
||||
stty -echo
|
||||
read -r "$1"
|
||||
stty echo
|
||||
|
||||
printf '\n'
|
||||
}
|
||||
|
||||
glob() {
|
||||
# This is a simple wrapper around a case statement to allow
|
||||
# for simple string comparisons against globs.
|
||||
|
|
Loading…
Reference in New Issue