blob: 04d4f49485573050e8842f5106922e30595642db (
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
|
#!/usr/bin/env bash
# Filename: makepass.bash
# Purpose: Creating random passwords.
# Authors: Dennis Eriksen <d@ennis.no>
# Bug-Reports: Email <git@dnns.no>
# License: This file is licensed under the BSD 3-Clause license.
################################################################################
# This file takes randomness from /dev/urandom and turns it into random
# passwords.
################################################################################
# Copyright (c) 2018-2023 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=bash filetype=bash
|