blob: 0ebc60bc40472564c18bdad228d4d5d44dfedf80 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
|