Skip to content

Instantly share code, notes, and snippets.

@leap0x7b
Created January 10, 2021 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leap0x7b/8db89d6378051f3c3b1505a902c9b04e to your computer and use it in GitHub Desktop.
Save leap0x7b/8db89d6378051f3c3b1505a902c9b04e to your computer and use it in GitHub Desktop.
Dialog-based password changer script
#!/bin/bash
## This script made to change your password with TUI dialog
## Original script made by NixCraft
## https://bash.cyberciti.biz/guide/A_password_box
# password storage
if [[ "$EUID" -ne 0 ]]; then
old=$(tempfile 2>/dev/null)
fi
new=$(tempfile 2>/dev/null)
# trap it
if [[ "$EUID" -ne 0 ]]; then
trap "rm -f $old" 0 1 2 5 15
fi
trap "rm -f $new" 0 1 2 5 15
# get password with the --insecure option
if [[ "$EUID" -ne 0 ]]; then
dialog --title "Password" \
--insecure \
--passwordbox "Enter your current password" 8 50 2> $old
fi
dialog --title "Password" \
--insecure \
--passwordbox "Enter your new password" 8 50 2> $new
ret=$?
# make decison
case $ret in
0)
if [[ "$EUID" -ne 0 ]]; then
echo -e "$(cat $old)\n$(cat $new)\n$(cat $new)" | passwd $1 2> /dev/null
else
echo -e "$(cat $new)\n$(cat $new)" | passwd $1 2> /dev/null
fi
;;
1)
echo "Cancel pressed.";;
255)
[ -s $data ] && cat $data || echo "ESC pressed.";;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment