Skip to content

Instantly share code, notes, and snippets.

@cagcak
Created June 27, 2017 21:12
Show Gist options
  • Save cagcak/cdf543065b1e28121a2e9feff4d97be4 to your computer and use it in GitHub Desktop.
Save cagcak/cdf543065b1e28121a2e9feff4d97be4 to your computer and use it in GitHub Desktop.
Simple user-interaction based bash login script
#!/bin/bash
# Simple user-interaction based login script
username="root"
password="toor"
#set -x #tracing code line on
echo "You have 10 sec to type"
echo -n "username > "
if read -t 10 response; then
if [ $response = $username ]; then
echo "hello $username"
echo -n "password > "
else
echo "user not found"
exit
fi
if read -s -t 10 response; then
if [ $response = $password ]; then
echo "login success"
# This line is where the actual magic starts
echo "logging out."
else
echo "wrong password"
fi
else
echo "Sorry! too slow"
echo "You should type credendials in 10 sec"
fi
else
echo "Sorry! Too slow!"
echo "Session timed out"
fi
#set +x #tracing code line off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment