Deepak_Bhatta_KAji

Sell ScriptingCheck Linux usernand password are valid or not

Dec 6th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. read -p "Enter the Username: " USERNAME
  4.  
  5. id -u $USERNAME > /dev/null
  6. if [ $? -ne 0 ]
  7. then
  8. echo "User $USERNAME is not valid"
  9. exit 1
  10. else
  11. echo "Enter the Password:"
  12. read -s PASSWD
  13. export PASSWD
  14. ORIGPASS=`grep -w "$USERNAME" /etc/shadow | cut -d: -f2`
  15. export ALGO=`echo $ORIGPASS | cut -d'$' -f2`
  16. export SALT=`echo $ORIGPASS | cut -d'$' -f3`
  17. GENPASS=$(perl -le 'print crypt("$ENV{PASSWD}","\$$ENV{ALGO}\$$ENV{SALT}\$")')
  18. if [ "$GENPASS" == "$ORIGPASS" ]
  19. then
  20. echo "Valid Username-Password Combination"
  21. exit 0
  22. else
  23. echo "Invalid Username-Password Combination"
  24. exit 1
  25. fi
  26. fi
Add Comment
Please, Sign In to add comment