Skip to content

Instantly share code, notes, and snippets.

@dotysan
Created June 17, 2016 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotysan/aeafeb8cf317137b2e899ecbada02044 to your computer and use it in GitHub Desktop.
Save dotysan/aeafeb8cf317137b2e899ecbada02044 to your computer and use it in GitHub Desktop.
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