Skip to content

Instantly share code, notes, and snippets.

@leap0x7b
Created January 11, 2021 05:11
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/aede4e9f3b96cf1358023388eaf876d2 to your computer and use it in GitHub Desktop.
Save leap0x7b/aede4e9f3b96cf1358023388eaf876d2 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
new=$(tempfile 2>/dev/null)
# trap it
trap "rm -f $new" 0 1 2 5 15
# get password with the --insecure option
dialog --title "Password" \
--insecure \
--passwordbox "Enter your new password" 8 50 2> $new
ret=$?
# make decison
case $ret in
0)
echo -e "${1-$USER}:$(cat $new)" | sudo chpasswd 2> /dev/null;;
*)
echo "Canceled.";;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment