Advertisement
Guest User

Untitled

a guest
Apr 26th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #!/bin/bash
  2. PASSFILE='/home/valio/passes/passes'
  3.  
  4. function genpasswd () {
  5. USER=$1
  6. PASS=$2
  7. DESC=$3
  8. PASSWRDINT=`echo $PASS | openssl enc -aes-256-cbc -a -salt -pass pass:$SALT`
  9. echo "$USER:$PASSWRDINT:$DESC" >> $PASSFILE
  10. return 1
  11. }
  12.  
  13. function getpasswd () {
  14. PASS=`grep -i $1 $PASSFILE | cut -d':' -f2`
  15. echo -n "User: "; echo `grep -i $1 $PASSFILE | cut -d':' -f1`
  16. echo -n "Password: "; echo $PASS | openssl enc -aes-256-cbc -a -d -salt -pass pass:$SALT
  17. echo "Description: " `grep -i $1 $PASSFILE | cut -d':' -f3`
  18. }
  19.  
  20. function listpasswd () {
  21. { echo "Available users:"
  22. while IFS=':' read user pass desc
  23. do
  24. echo "$user / $desc"
  25. done } < $PASSFILE
  26. }
  27.  
  28. function usage () {
  29. echo "Usage:
  30. -p | --genpasswd - Generate password for the user. It takes 3 arguements. Example: passes -p <USER> <PASSWORD> <DESCRIPTION>
  31. -g | --getpasswd - Get decrypted password for the user. Example: passes -g <DESC>
  32. -l | --list - List available users and their descriptions
  33. "
  34. }
  35. if [ "$1" == "-h" ]
  36. then
  37. usage
  38. elif [ $1 == "-l" ]
  39. then
  40. listpasswd
  41. else
  42. read -s -p "Passphrase: " SALT
  43. fi
  44.  
  45. while [ "$1" != "" ];do
  46. case $1 in
  47. -p | --genpasswd ) shift
  48. genpasswd $1 $2 $3
  49. ;;
  50. -g | --getpasswd ) shift
  51. getpasswd $1
  52. ;;
  53. -l | --list ) shift
  54. listpasswd
  55. ;;
  56.  
  57. -h | --help ) usage
  58. exit
  59. ;;
  60. "" ) usage
  61. exit
  62. ;;
  63. esac
  64. shift
  65. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement