Create Strong passwords in BASH Script

OK, this has been answered a couple of times before:

http://unifix.org/cgi-bin/index.pl?action=show&ID=193
http://unifix.org/cgi-bin/index.pl?action=show&ID=203

But none of those scripts actually test for password strength :-)

Debug mode:

LOOP=1
PASSWORD=""
until [[ $PASSWORD =~ [a-z].*[a-z] ]] && [[ $PASSWORD =~ [A-Z].*[A-Z] ]] && [[ $PASSWORD =~ [0-9].*[0-9] ]]
do 
   PASSWORD=$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c${1:-8})
   echo $LOOP
   LOOP=$(($LOOP+1))
done
echo $PASSWORD

Most of the time I get a strong password in max 5 to 7 loops.
The record was 21 (wtf debian? RNG broken again?)

Actual scrip snippet:

create_password() {
   PASSWORD=""
   until [[ $PASSWORD =~ [a-z].*[a-z] ]] && [[ $PASSWORD =~ [A-Z].*[A-Z] ]] && [[ $PASSWORD =~ [0-9].*[0-9] ]]
   do 
      PASSWORD=$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c${1:-8})
   done
   echo "$PASSWORD"
}

NEW_USER_PASSWORD=$(create_password)

Success!
Dette indlæg blev udgivet i Knowledge Base. Bogmærk permalinket.

Skriv et svar