aboutsummaryrefslogtreecommitdiffstats
path: root/makepass.sh
diff options
context:
space:
mode:
Diffstat (limited to 'makepass.sh')
-rwxr-xr-xmakepass.sh20
1 files changed, 11 insertions, 9 deletions
diff --git a/makepass.sh b/makepass.sh
index 3af6830..bb56aef 100755
--- a/makepass.sh
+++ b/makepass.sh
@@ -21,9 +21,11 @@ makepass() {
# We only take one argument
[ "$#" -gt 1 ] && printf '%s\n' 'only one argument' && return 1
- # if $1 is not empty and is not a number
- if [ ! -z "$1" ] && ! printf '%d' "$1" >/dev/null 2>&1; then printf '%s\n' 'not a number' && return 1; fi
- if [ ! -z "$1" ] && [ ! ${1:-0} -gt 0 ]; then printf '%s\n' 'not a number above 0'; return 1; fi
+ # check if $1 is a number or whatnot
+ if [ -n "$1" ]; then
+ if ! printf '%d' "$1" >/dev/null 2>&1; then printf '%s\n' 'not a number' && return 1; fi
+ if [ "$1" -le 0 ] || [ "$1" -ge 255 ]; then printf '%s\n' 'not a number above 0'; return 1; fi
+ fi
# Go!
len=$1
@@ -31,7 +33,7 @@ makepass() {
printf '%s\n' 'Normal passwords:'
i=0
while [ $i -lt 10 ]; do
- _random "${len:-}" '_A-Z-a-z-0-9' true
+ _random "${len:-}" 'A-Z-a-z-0-9_-' true
i=$((i + 1))
done | column
printf '\n'
@@ -46,7 +48,7 @@ makepass() {
if [ -r "${MAKEPASS_WORDLIST}" ]; then
printf '\n'
printf '%s\n' 'Passphrases:'
- lines=$(wc -l < ${MAKEPASS_WORDLIST})
+ lines=$(wc -l < "${MAKEPASS_WORDLIST}")
i=0
while [ $i -lt 5 ]; do
# shuf is the best solution here, but it is very much not portable.
@@ -54,7 +56,7 @@ makepass() {
words=""
j=0
while [ $j -lt 8 ]; do
- words="${words}-$(sed -n $(($(_RANDOM) % $lines + 1))p "${MAKEPASS_WORDLIST}" | tr -dc '_A-Z-a-z-0-9')"
+ words="${words}-$(sed -n $(($(_RANDOM) % lines + 1))p "${MAKEPASS_WORDLIST}" | tr -dc 'A-Z-a-z-0-9_-')"
j=$((j + 1))
done
printf '%s\n' "${words#-}"
@@ -89,15 +91,15 @@ _random() (
fla=${3:-'false'}
if [ "$fla" = "true" ]; then
- if [ $len -le 2 ]; then
- string="$(head -n 10 /dev/urandom | tr -cd '[:alpha:]' | tail -c $len)"
+ if [ "$len" -le 2 ]; then
+ string="$(head -n 10 /dev/urandom | tr -cd '[:alpha:]' | tail -c "$len")"
else
string="$(head -n 10 /dev/urandom | tr -cd '[:alpha:]' | tail -c 1)"
string="${string}$(head -n 100 /dev/urandom | tr -cd "$chars" | tail -c $((len-2)))"
string="${string}$(head -n 10 /dev/urandom | tr -cd '[:alpha:]' | tail -c 1)"
fi
else
- string="$(head -n 100 /dev/urandom | tr -cd "$chars" | tail -c $len)"
+ string="$(head -n 100 /dev/urandom | tr -cd "$chars" | tail -c "$len")"
fi
printf '%s\n' "$string"