Friday, April 3, 2009

Random password generator

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

#!/bin/bash

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

clear

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

length=$1

[ -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
fi

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: