Option to read password by username

This commit is contained in:
drduh 2015-07-03 00:16:37 -04:00
parent 25122d0549
commit c8e0f6d494
2 changed files with 8 additions and 2 deletions

View File

@ -20,7 +20,7 @@ Run the script with `./pwd.sh`
Type `w` to write a password.
Type `r` to read passwords. Pipe to `grep` and `pbcopy` or `xsel`, for example.
Type `r` to read a password or all passwords.
Type `d` to delete a password.

8
pwd.sh
View File

@ -59,11 +59,15 @@ encrypt () {
read_pass () {
# Read a password from safe.
if [[ -z ${username} || ${username} == "all" ]] ; then
username=""
fi
if [ ! -s ${safe} ] ; then
fail "No passwords found"
else
get_pass "Enter password to unlock ${safe}: " ; echo
decrypt ${password} ${safe} || fail "Decryption failed"
decrypt ${password} ${safe} | grep " ${username}" || fail "Decryption failed"
fi
}
@ -120,6 +124,7 @@ create_username () {
userpass=$password
else
userpass=$(gen_pass)
echo "Password: ${userpass}"
fi
}
@ -143,6 +148,7 @@ elif [ "${action}" == "d" ] ; then
read -p "Username to delete? " username
write_pass
else
read -p "Username to read? (default: all) " username
read_pass
fi