aboutsummaryrefslogtreecommitdiffstats
path: root/makepass.bash
diff options
context:
space:
mode:
Diffstat (limited to 'makepass.bash')
-rwxr-xr-xmakepass.bash59
1 files changed, 59 insertions, 0 deletions
diff --git a/makepass.bash b/makepass.bash
new file mode 100755
index 0000000..0ebc60b
--- /dev/null
+++ b/makepass.bash
@@ -0,0 +1,59 @@
+#!/usr/bin/env bash
+# Filename: ~/bin/makepass
+# Purpose: Creating random passwords.
+# Authors: Dennis Eriksen <d@ennis.no>
+# Some parts have been shamelessly stolen from other places.
+# These parts will normally have a comment saying where it's
+# from. For instance, this header format is stolen from the
+# GRML-team (grml.org).
+# Bug-Reports: Email <idgatt@dnns.no>
+# License: This file is licensed under the GPL v2.
+################################################################################
+# This file takes randomness from /dev/urandom and turns it into random
+# passwords.
+################################################################################
+
+
+# Copyright (c) 2018 Dennis Eriksen • d@ennis.no
+
+# makepass-function
+function makepass {
+ local l=$1
+ local words
+ local first
+ local last
+ MAKEPASS_WORDLIST=${MAKEPASS_WORDLIST:-/usr/share/dict/words}
+ # if $l is not a number, then exit
+ [[ ! $l =~ ^[0-9]+$ ]] && [[ ! "$l" == "" ]] && echo "not a number" && return 1
+ # if $1 is actually empty, set $l to random value for each output
+ echo "Normal passwords:"
+ for i in {1..10}; do
+ [ "$1" = "" ] && l=$(shuf -i 8-44 -n 1)
+ head -n10 /dev/urandom | tr -dc _A-Z-a-z-0-9 | cut -c-${1:-$l};
+ done | column
+ echo ""
+
+ echo "Passwords with special characters:"
+ for i in {1..6}; do
+ [ "$1" = "" ] && l=$(shuf -i 16-64 -n 1)
+ first=$(head -n10 /dev/urandom | tr -dc A-Za-z | cut -c-1)
+ words=$(head -n10 /dev/urandom | tr -dc '!#$%&/()=?+-_,.;:<>[]{}|\@*^A-Z-a-z-0-9' | cut -c-${1:-$l})
+ last=$(head -n10 /dev/urandom | tr -dc A-Za-z | cut -c-1)
+ echo "${first}${words}${last}"
+ done | column
+
+ if [ -r "${MAKEPASS_WORDLIST}" ]; then
+ echo ""
+ echo "Passphrases:"
+
+ for i in {1..5}; do
+ words=$(shuf -n 8 "${MAKEPASS_WORDLIST}" | tr '\n' '-' | tr -dc '_A-Z-a-z-0-9')
+ echo "${words:0:-1}"
+ done;
+ fi
+}
+
+makepass "${@:-}"
+
+## END OF FILE #################################################################
+# vim:syntax=sh filetype=sh