site  contact  subhomenews

Toggle show or hide password in initrd

October 28, 2025 — BarryK

I was testing the German (de) keyboard layout, and thought that I had gone back to US layout, which is my actual keyboard. At next bootup, my password was wrong, and I couldn't figure out why.

Then of course, the penny dropped, was still on the German keyboard layout. Which lead to the thought, it would be good to be able to toggle the display of the password to show the actual password, not star characters.

So have implemented it. The 'init' script in the initrd has this:

  SHOWpw=0 #20251028 toggle show pw
while [ 1 ];do
echo -e "\\e[1;;44m ${S039:-Please enter password to decrypt the working-partition} \\e[0;;m" #
echo -e "\\e[1;;44m ${S550:-(press SPACE character to show or hide password)} \\e[0;;m" #
echo -e "\\e[1;;43m ${S040:-OR just press ENTER to bring up a menu of boot options} \\e[0;;m" #43=yellow background.
echo -n " ${S041:-Password:} "
PW=''
while [ 1 ];do #echo * for each char entered...
IFS='' read -r -s -n1 pw1
if [ -z "$pw1" ];then
echo; break
else
if [ "$pw1" == " " ];then
#echo -ne "\r\033[2K" will return cursor to start and erase current line...
if [ $SHOWpw -eq 0 ];then SHOWpw=1; echo -ne "\r\033[2K ${S041:-Password:} ${PW}"; continue; fi
if [ $SHOWpw -eq 1 ];then SHOWpw=0; echo -ne "\r\033[2K ${S041:-Password:} ${PW//?/*}"; continue; fi
fi
if [ $SHOWpw -eq 1 ];then
echo -n "${pw1}"; PW="${PW}${pw1}"
else
echo -n '*'; PW="${PW}${pw1}"
fi
fi
done

Not tested yet, but looks correct.    

Tags: easy