Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- PASSFILE='/home/valio/passes/passes'
- function genpasswd () {
- USER=$1
- PASS=$2
- DESC=$3
- PASSWRDINT=`echo $PASS | openssl enc -aes-256-cbc -a -salt -pass pass:$SALT`
- echo "$USER:$PASSWRDINT:$DESC" >> $PASSFILE
- return 1
- }
- function getpasswd () {
- PASS=`grep -i $1 $PASSFILE | cut -d':' -f2`
- echo -n "User: "; echo `grep -i $1 $PASSFILE | cut -d':' -f1`
- echo -n "Password: "; echo $PASS | openssl enc -aes-256-cbc -a -d -salt -pass pass:$SALT
- echo "Description: " `grep -i $1 $PASSFILE | cut -d':' -f3`
- }
- function listpasswd () {
- { echo "Available users:"
- while IFS=':' read user pass desc
- do
- echo "$user / $desc"
- done } < $PASSFILE
- }
- function usage () {
- echo "Usage:
- -p | --genpasswd - Generate password for the user. It takes 3 arguements. Example: passes -p <USER> <PASSWORD> <DESCRIPTION>
- -g | --getpasswd - Get decrypted password for the user. Example: passes -g <DESC>
- -l | --list - List available users and their descriptions
- "
- }
- if [ "$1" == "-h" ]
- then
- usage
- elif [ $1 == "-l" ]
- then
- listpasswd
- else
- read -s -p "Passphrase: " SALT
- fi
- while [ "$1" != "" ];do
- case $1 in
- -p | --genpasswd ) shift
- genpasswd $1 $2 $3
- ;;
- -g | --getpasswd ) shift
- getpasswd $1
- ;;
- -l | --list ) shift
- listpasswd
- ;;
- -h | --help ) usage
- exit
- ;;
- "" ) usage
- exit
- ;;
- esac
- shift
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement