Skip to content

Instantly share code, notes, and snippets.

@thibthibaut
Created March 20, 2017 14:47
Show Gist options
  • Save thibthibaut/986642f62570408d5f73cbd728da88b6 to your computer and use it in GitHub Desktop.
Save thibthibaut/986642f62570408d5f73cbd728da88b6 to your computer and use it in GitHub Desktop.
The world simplest password manager
#!/bin/bash
#------------------------------------------------------------------------------
# passmgr.sh
# The world simplest password manager ever
# by Aehter Luminifer
# Dependancies:
# * pwgen
# * gpg
# Version: 3.14
# Licence :
# "THE BEER-WARE LICENSE" (Revision 42):
# Thibaut Vercueil wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return Thibaut Vercueil
#------------------------------------------------------------------------------
#Test if database exists
if [ ! -f "~/passwords.gpg" ]; then
touch ~/passwords.gpg
fi
if [ "$1" == "-a" ]; then
if [ "$2" == "" ]; then
echo "Please give a name to the password!"
exit
fi
echo "Adding new password to database..."
pw=`pwgen -s -y 12 1` #Generate password
gpg --output /tmp/pw -d ~/passwords.gpg #Decrypt current passwords
echo "$2 $pw" >> /tmp/pw #Add new password
shred -f -n 10 -u -z ~/passwords.gpg #Remove old database
gpg --output ~/passwords.gpg --symmetric /tmp/pw #Rewritte database
shred -f -n 10 -u -z /tmp/pw #Remove clear file
echo "Done"
elif [ "$1" == "-r" ]; then
if [ "$2" == "" ]; then
echo "Please provide a name to search in DB"
exit
fi
echo "Retriving password from database"
gpg --output /tmp/pw -d ~/passwords.gpg #Decrypt current passwords
result=`cat /tmp/pw | grep $2` #Look for the entry
shred -f -n 10 -u -z /tmp/pw #Remove clear file
if [ "$result" == "" ]; then
echo "No entry found for $2"
else
echo "$result"
fi
echo "Done"
else
echo "Welcome to passmgr.sh by aether!"
echo "Usage:"
echo "To add a new password: ./passmgr.sh -a facebook"
echo "To retrieve a password: ./passmgr.sh -r facebook"
echo "Big Bisous is watching you!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment