Created
December 15, 2020 23:49
-
-
Save dougpagani/8e8b9fc761da1cf4bd91e131e9dfc9c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
unset PASSWORD | |
unset CHARCOUNT | |
echo -n "Enter password: " | |
stty -echo | |
CHARCOUNT=0 | |
while IFS= read -p "$PROMPT" -r -s -n 1 CHAR | |
do | |
# Enter - accept password | |
if [[ $CHAR == $'\0' ]] ; then | |
break | |
fi | |
# Backspace | |
if [[ $CHAR == $'\177' ]] ; then | |
if [ $CHARCOUNT -gt 0 ] ; then | |
CHARCOUNT=$((CHARCOUNT-1)) | |
PROMPT=$'\b \b' | |
PASSWORD="${PASSWORD%?}" | |
else | |
PROMPT='' | |
fi | |
else | |
CHARCOUNT=$((CHARCOUNT+1)) | |
PROMPT='*' | |
PASSWORD+="$CHAR" | |
fi | |
done | |
stty echo | |
echo $PASSWORD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment