1
0
mirror of https://github.com/octoleo/Purse.git synced 2024-06-02 06:30:47 +00:00

Support password length command line argument when generating and writing passwords

This commit is contained in:
drduh 2015-07-31 00:35:35 -04:00
parent aaa35414a9
commit 62ce715108
2 changed files with 20 additions and 9 deletions

View File

@ -8,9 +8,7 @@ Script to manage passwords in an encrypted file using gpg.
git clone https://github.com/drduh/pwd.sh && cd pwd.sh git clone https://github.com/drduh/pwd.sh && cd pwd.sh
Requires `gpg` Requires `gpg`. Install with `brew install gpg` or `sudo apt-get install gnupg` or build and install it from [source](https://www.gnupg.org/download/index.html).
Install with `brew install gpg` or `sudo apt-get install gnupg` or build and install it from [source](https://www.gnupg.org/download/index.html).
# Use # Use
@ -22,10 +20,14 @@ Type `r` to read a password(s).
Type `d` to delete a password. Type `d` to delete a password.
Or, the action and username can be passed on the command line, e.g., Options can also be passed on the command line, e.g.,
`./pwd.sh r github` or `./pwd.sh w gmail` `./pwd.sh w gmail 30` to generate and write a password called 'gmail' with a length of 30 characters, or
The encrypted file `pwd.sh.safe` and script can be safely shared between machines over public channels (Google Drive, Dropbox, etc). `./pwd.sh r github` to read the password called 'github', or
`./pwd.sh d dropbox` to delete the password called 'dropbox'.
The script and `pwd.sh.safe` encrypted file can be safely shared between machines over public channels (Google Drive, Dropbox, etc).
A sample `gpg.conf` configuration file is provided for your consideration. A sample `gpg.conf` configuration file is provided for your consideration.

13
pwd.sh
View File

@ -95,8 +95,13 @@ gen_pass () {
len=50 len=50
max=100 max=100
if [[ -z "${3+x}" ]] ; then
read -p " read -p "
Password length? (default: ${len}, max: ${max}) " length Password length? (default: ${len}, max: ${max}) " length
else
length="${3}"
fi
if [[ ${length} =~ ^[0-9]+$ ]] ; then if [[ ${length} =~ ^[0-9]+$ ]] ; then
len=${length} len=${length}
@ -142,11 +147,15 @@ create_username () {
if [[ -z "${2+x}" ]] ; then if [[ -z "${2+x}" ]] ; then
read -p " read -p "
Username: " username Username: " username
else
username="${2}"
fi
if [[ -z "${3+x}" ]] ; then
read -p " read -p "
Generate password? (y/n, default: y) " rand_pass Generate password? (y/n, default: y) " rand_pass
else else
rand_pass="" rand_pass=""
username="${2}"
fi fi
if [[ "${rand_pass}" =~ ^([nN][oO]|[nN])$ ]]; then if [[ "${rand_pass}" =~ ^([nN][oO]|[nN])$ ]]; then
@ -154,7 +163,7 @@ create_username () {
Enter password for \"${username}\": " ; echo Enter password for \"${username}\": " ; echo
userpass=$password userpass=$password
else else
userpass=$(gen_pass) userpass=$(gen_pass "$@")
echo " echo "
Password: ${userpass}" Password: ${userpass}"
fi fi