formsdialog

Can we mask a particular field in dialog?


I am using dialog in a Bash program, to request that the user fill out several fields. I want to mask the password that the user is typing in.

dialog  --title "Server address and login credentials" --form "$msg" 14 60 5 \
"Server Address:   " 1 1 "" 1 20 30 50 \
"Server Port:   " 2 1 "" 2 20 30 50 \
"Gateway Address:" 3 1 "" 3 20 30 50 \
"Logon Name:   " 4 1 "" 4 20 30 50 \
"Logon Password:   " 5 1 "" 5 20 30 50

While the --passwordbox is supported, it will obscure all fields. which is not what I desire. While reading, I tried passing the -s -p option (read -p -s password), but it did not work. I've read that we can use the --password-mask function, but I'm not sure how to utilize it.

How can I prevent the logon password being visible?


Solution

  • I did some research and learned that the mixedform option can be used to get the expected behaviour.

    The value in the last column controls masking. The value of the specific field is masked by setting the last column value to 1.

    dialog --title "Server address and login credentials" --insecure --mixedform "Server Details" 14 60 5
    "Server Address: " 1 1 "" 1 20 30 50 0
    "Server Port: " 2 1 "" 2 20 30 50 0
    "Gateway Address:" 3 1 "" 3 20 30 50 0
    "Logon Name: " 4 1 "" 4 20 30 50 0
    "Logon Password: " 5 1 "" 5 20 30 50 1 2> /dev/null

    Reference link: https://www.unix.com/shell-programming-and-scripting/63682-dialog-menu-script-please-help.html