Created
October 3, 2018 17:43
-
-
Save queertypes/14e835a3801b609bde5cae22123a8626 to your computer and use it in GitHub Desktop.
A simple CLI password generator built on /dev/urandom and Unix tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# A simple password generator that uses a combination of /dev/urandom, | |
# tr, head, and xclip to quickly generate a reasonably random password | |
## strict bash mode | |
set -euo pipefail | |
IFS=$'\n\t' | |
## pwgen [count] [allowed-symbols] | |
### password length is 16 by default | |
readonly COUNT=${1:-16} | |
### use all symbols by default | |
readonly SYMBOLS=${2:-'/\-[]{};:",.<>?!@#$%^&*()=+\\'"'"} | |
### if you provide a non-empty value for the allowed symbols, | |
### guarantee that as least alphanumeric character will be in the | |
### password | |
readonly BASE_SYMBOLS='A-Za-z0-9' | |
readonly FULL_SYMBOLS="$BASE_SYMBOLS""$SYMBOLS" | |
## store generated password in clipboard | |
readonly PASS=$(< /dev/urandom tr -dc "$FULL_SYMBOLS" | head -c"$COUNT") | |
echo -n "$PASS" | xclip -sel clip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment