From c8e0f6d4945496bde3d3735c60a2a64fdf1d0c3d Mon Sep 17 00:00:00 2001 From: drduh Date: Fri, 3 Jul 2015 00:16:37 -0400 Subject: [PATCH] Option to read password by username --- README.md | 2 +- pwd.sh | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c91ed12..383fb38 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/pwd.sh b/pwd.sh index cef424a..7b80ba5 100755 --- a/pwd.sh +++ b/pwd.sh @@ -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