Friday, April 3, 2009

Random password generator

A little handy script that will help you generate random passwords:


#Written by Paul.P - 2.4.2009
#The script generates a random password, argument $1 sets password length


#If no argument passed - default length of 12 will be used


[ -n "$length" ] || length=12;echo "no arguments passed, using default length (12)"

#Strength check
if [ "$length" -lt 8 ];then
echo "the password of $length characters length is not strong enough."
exit 1

password=$(dd if=/dev/urandom bs=512 count=1 2> /dev/null | tr -cd 'a-zA-Z0-9' \
| cut -c 1-$length)
echo "$password"

No comments: