-
Notifications
You must be signed in to change notification settings - Fork 0
/
random-password
executable file
·93 lines (91 loc) · 2.48 KB
/
random-password
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh
set -euf
##
# Generate a random password for high security needs.
#
# Usage:
#
# random-password [n] [characters]
#
# Options:
#
# * n is an optional length; default is 24.
# * characters is a string; default is "abcdefghijklmnop"
#
# Examples:
#
# $ random-password
# eoejnagpilnajfcmagffheie
#
# $ random-password 8
# midbpjkc
#
# $ random-password 8 abc
# bccabbcb
#
#
# ## Implementation
#
# This uses /dev/urandom to generate random characters.
# This is high security and suitable for cryptography.
#
# This script filters the stream of characters to pick just
# the ones that match the given characters.
#
#
# ## Configuration
#
# The default configuration is to match the first 16 letters
# in the English alphabet, namely "abcdefghijklmnop".
#
# We choose to use exactly 16 characters because this
# means each character has 2^4 bits of random information,
# which is equivalent to one hexadecimal character.
#
# This has valuable mathematical properties for generating
# security values at high speed, and for calculating password
# strength, and for transforming among bits and characters.
#
# Some password-checker tools may report these passwords
# are insecure because they only have lowercase letters.
# This is not true for these passwords with the settings
# that we use i.e. secure random 24 picks of 16 characters.
#
# Mathematically, using 24 picks of 16 different characters
# is more computationally secure than 12 mixed characters,
# such as typical for passwords generated by Amazon.com for
# high security server sign in and system administration.
#
# We choose lowercase letters, rather than hexadecimal,
# because it's easier for most users to type many lowercase
# letters on most keyboards, especially on mobile devices.
#
#
# ## Customization
#
# If you prefer to use different security, use more picks,
# or different characters, or both.
#
# For example if you prefer to use 12 picks of hexadecimals:
#
# random-password 12 "0123456789ABCDEF"
# D22DCF30358B
#
# For example if you prefer to use 12 picks including symbols:
#
# random-password 12 "\!\@\#\$ABCD"
# B!$!ADB@$!!A$
#
#
# ## Tracking
#
# * Command: random-password
# * Version: 4.1.0
# * Created: 2010-05-20
# * Updated: 2021-10-14T17:58:40Z
# * License: BSD or MIT or GPL or contact us for custom license
# * Contact: Joel Parker Henderson ([email protected])
##
len=${1-24}
chars=${2-"abcdefghijklmnop"}
LC_ALL=C < /dev/urandom tr -dc "$chars" | head -c"$len"