forked from ChrisKaufmann/totools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpwgen
More file actions
executable file
·39 lines (31 loc) · 722 Bytes
/
pwgen
File metadata and controls
executable file
·39 lines (31 loc) · 722 Bytes
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
#!/bin/bash
#via: http://thdonline.wordpress.com/2009/03/14/shell-script-to-generate-random-password/
#with a slight modification for my preferences
MAXSIZE=$1
if [ "$MAXSIZE" != "" -a "$MAXSIZE" == "${MAXSIZE//[^0-9]/}" ]
then
#I don't like the extra output
MAXSIZE=$MAXSIZE
else
MAXSIZE=16
fi
CHAR_ARRAY=(
q w e r t y u i o p a s d f g h j k l z x c v b n m Q W E R T Y U I O P A S D
F G H J K L Z X C V B N M 1 2 3 4 5 6 7 8 9 0 ! @ # $ % ^ & * ( )
)
MODNUM=${#CHAR_ARRAY[*]}
PWD_LEN=0
while [ $PWD_LEN -lt $MAXSIZE ]
do
X=$(($RANDOM%500))
Y=0
while [ $Y -lt $X ]
do
((Y++))
INDEX=$(($RANDOM%$MODNUM))
done
echo -n "${CHAR_ARRAY[$INDEX]}"
((PWD_LEN++))
done
echo ""
exit 0