From 09adcb0b95a16fe30f00379855b76052501aa3f9 Mon Sep 17 00:00:00 2001 From: drduh Date: Fri, 7 Aug 2015 14:11:11 -0400 Subject: [PATCH] Fast fail if password file is missing. --- README.md | 4 +++- pwd.sh | 18 +++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2e0ace2..eb7bd92 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,9 @@ The script and `pwd.sh.safe` encrypted file can be safely shared between machine A sample `gpg.conf` configuration file is provided for your consideration. -# Alternatives +# Recommended software [Pass: the standard unix password manager](http://www.passwordstore.org/) +[sf-pwgen: generates passwords using OS X Security framework](https://github.com/anders/pwgen) + diff --git a/pwd.sh b/pwd.sh index 27a5775..77b969a 100755 --- a/pwd.sh +++ b/pwd.sh @@ -68,25 +68,25 @@ encrypt () { read_pass () { # Read a password from safe. + if [[ ! -s ${safe} ]] ; then + fail "No passwords found" + fi + if [[ -z "${2+x}" ]] ; then read -p " Username to read? (default: all) " username else - username="${2}" + username="${2}" fi if [[ -z ${username} || ${username} == "all" ]] ; then username="" fi - if [[ ! -s ${safe} ]] ; then - fail "No passwords found" - else - get_pass " + get_pass " Enter password to unlock ${safe}: " - printf "\n\n" - decrypt ${password} ${safe} | grep " ${username}" || fail "Decryption failed" - fi + printf "\n\n" + decrypt ${password} ${safe} | grep " ${username}" || fail "Decryption failed" } @@ -167,7 +167,7 @@ create_username () { fi if [[ -z "${4+x}" || ! "${4}" =~ ^([qQ])$ ]] ; then - echo " + echo " Password: ${userpass}" fi }