Guest User

Untitled

a guest
Aug 22nd, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.75 KB | None | 0 0
  1. #! /bin/bash
  2. #Simple Login script made in $Bash!
  3. #It has improved a lot than before, but still insecure :P
  4. #Written by Sars!
  5. #Version: 0.8
  6.  
  7. #Path where the valuables are stored.
  8. pt=../usr/share/.login
  9. #Path for temporarily storing unencrypted valuables.
  10. opt=../usr/tmp/.tmplog
  11.  
  12. #Function for encrypting & decrypting cred.
  13. encrypt() {
  14. openssl enc -aes-256-cbc -pbkdf2 -salt -in $opt -out $pt -k $pf 2>/dev/null #Redirects error if any to /dev/null. Thanks to https://stackoverflow.com/a/25348167
  15. chmod u-rw $pt
  16. }
  17.  
  18. decrypt() {
  19. chmod u+rw $pt
  20. openssl enc -d -aes-256-cbc -pbkdf2 -salt -in $pt -out $opt -k $pss 2>/dev/null #Redirects bad-decrypts error if any to /dev/null. Thanks to https://stackoverflow.com/a/25348167
  21. }
  22.  
  23. #Function that sets credentials.
  24. st_crd() {
  25.     read -p "Set Your Username: " un
  26.     read -s -p "Set Your Password: " pf
  27.  
  28.     #rm the unencrypted cred file if it exists
  29.     if [ -f $opt ];
  30.     then
  31.         rm $opt
  32.     fi
  33.  
  34.     if [[ $un != "" && $pf != "" ]];
  35.     then
  36.         touch $pt
  37.         echo -e "$un\n$pf" >> $opt
  38.         echo -e "\nCredentials added!!"
  39.         encrypt
  40.         echo -e "\nExiting Termux, please restart it!"
  41.         sleep 3
  42.         kill -9 $PPID
  43.     else
  44.         echo -e '\nCredentials cannot be empty!'
  45.         exit
  46.     fi
  47.  
  48. }
  49.  
  50. #Function for re-setting credentials.
  51. rst_crd() {
  52.     read -p "Enter Old Password: " pss
  53.     decrypt
  54.  
  55.     #Read the old pass.
  56.     op=$( tail -n 1 $opt 2>/dev/null )
  57.  
  58.     if [[ $pss == "$op" && $pss != "" ]];
  59.     then
  60.         echo -e "\nClearing your Old Credentials..."
  61.         rm -rf $pt
  62.         echo -e "\nCleared! Please add your new credentials"
  63.         st_crd
  64.  
  65.     else
  66.         echo -e "\nOh, you remember your Credentials? :o"
  67.         echo -e "\nClosing app, re-launch it please"
  68.         chmod u-rw $pt
  69.         sleep 3
  70.         kill -9 $PPID
  71.     fi
  72. }
  73.  
  74. #Trap the intruder & check if user wants to reset Credentials ;)
  75. int_trp() {
  76.     echo -e "\nForgot your Credentials?"
  77.     read ans
  78.  
  79.     if [[ $ans == "yes" || $ans == "y" || $ans == "Y" || $ans == "Yes" ]];
  80.     then
  81.         rst_crd
  82.  
  83.     else
  84.         echo "Intruder Alert!!"
  85.         chmod u-rw $pt
  86.         sleep 3
  87.         kill -9 $PPID
  88.     fi
  89. }
  90.  
  91. #Function for checking if the user is authorized.
  92. chk_crd() {
  93.     trap 'int_trp' INT
  94.     chmod u+rw $pt
  95.  
  96.     echo "Enter Username"
  97.     read n
  98.     echo "Enter Passwd"
  99.     read -s pss
  100.     decrypt
  101.  
  102.     unm=$( head -n 1 $opt 2>/dev/null )
  103.     p=$( tail -n 1 $opt 2>/dev/null )
  104.  
  105.     if [[ $n == "" || $pss == "" ]];
  106.     then
  107.         echo "Please Enter your Credentials... Exiting"
  108.         sleep 3
  109.         kill -9 $PPID
  110.  
  111.     elif [[ $n == "$unm" && $pss == "$p" ]];
  112.     then
  113.         echo "Welcome!"
  114.  
  115.     else
  116.         echo "Un-Authorized User ..exiting"
  117.         sleep 3
  118.         kill -9 $PPID
  119.     fi
  120.     chmod u-rw $pt
  121.     rm $opt
  122. }
  123.  
  124. #Checks if the user is running the script for first time, it's not the proper way of doing this i guess but for now it works :P
  125. if [ -f "$pt" ];
  126. then
  127.     chk_crd
  128.  
  129. else
  130.     st_crd
  131. fi
  132.  
  133. trap SIGINT
Add Comment
Please, Sign In to add comment