Skip to content

Instantly share code, notes, and snippets.

@andermoran
Created November 28, 2016 19:40
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 andermoran/1ae3230a37dcdfd1685b7883248acab3 to your computer and use it in GitHub Desktop.
Save andermoran/1ae3230a37dcdfd1685b7883248acab3 to your computer and use it in GitHub Desktop.
# Prompts user for password until the password is correct
# Useful for programs where you must get the correct password from the user in order to execute a command
passOk="false"
while [ "$passOk" != "true" ]
do
echo -n "Password: "
read password # Grabs username
if [[ $(echo $password | sudo -k -S echo valid) = "valid" ]] &>/dev/null; then
echo "Correct password"
passOk=true
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment