Skip to content

Instantly share code, notes, and snippets.

@dotysan
Created Jun 17, 2016
Embed
What would you like to do?
Cheap attempt to generate a random password and its crypt-pw using mostly bash.
#! /bin/bash -e
#
# Cheap attempt to generate a random password and its crypt-pw using mostly bash.
#
SALT="./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
mkapass() {
local len=${1-8}
while [ ${n:=1} -le $len ]
do let n+=1
pass="$pass${SALT:$[RANDOM%${#SALT}]:1}"
done
echo "$pass"
unset pass n
}
salt="${SALT:$[RANDOM%${#SALT}]:1}${SALT:$[RANDOM%${#SALT}]:1}"
pass=$(mkapass 11)
crypt=$(python -c "import crypt; print crypt.crypt('$pass','$salt')") #"
echo "password: $pass"
echo "crypt-pw: $crypt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment