The last script is not too bad.
You need to include the IFS= or the password read will abort on space or tab. Also add a -r option, otherwise a backspace at the end will escape the final newline. (A real painful bash default).
I would also include ' 08' (backspace) for character removal and ' 15' (^U or kill line)
to restart the password. But otherwise it is quite good.
Code:
' 15') # ^U or kill line
echo -n "$PWORD" | sed 's/./\cH \cH/g' >&2
PWORD=''
;;
NOTE that sed assumes GNU-sed.
If this could be a problem another alternative is
Code:
echo -n "$PWORD" | tr -c '\b' '\b' >&2
echo -n "$PWORD" | tr -c ' ' ' ' >&2
echo -n "$PWORD" | tr -c '\b' '\b' >&2
All it needs now is for it to not do prompt and star processing when the input is not a TTY! (just a straight pass-thru) and you have a simple (no-gui, no-curses) password reader.
Note if you know the input is from a TTY and wanted a "curses" version try "dialog"
Code:
dialog --stdout --insecure --passwordbox "Password:" 0 0
The --stdout causes the password out stdout and curse output to go direct to the TTY
This method like most GUI interfaces will not let you input TAB's.