Download this script

GeSHi © 2004-2007 Nigel McNie, 2007-2009 Benny Baumann, 2008-2009 Milian Wolff
  1. #!/bin/bash
  2.  
  3. weakString="Weak Password"
  4. strongPassword="Strong Password"
  5.  
  6. isWeakPassword() {
  7.     password=$1
  8.    
  9.     #Minimum length of 8 characters
  10.     if [ ${#password} -lt 8 ]
  11.     then
  12.         echo "$password: $weakString"
  13.         return
  14.     fi
  15.    
  16.     #Must contain at least one numeric character
  17.     if [ `echo $password | grep -c -E "[0-9]+"` -eq 0 ]
  18.     then
  19.         echo "$password: $weakString"
  20.         return 
  21.     fi
  22.    
  23.     #Must contain at least one of the following non-alphabetic characters: @, #, $, %, &, *, +, -, =
  24.     if [ `echo $password | grep -c -E "[@#$%&*=+-]+"` -eq 0 ]
  25.     then
  26.         echo "$password: $weakString"
  27.         return 
  28.     fi
  29.    
  30.     #Do a dictionary check on every sequence of at least four consecutive alphabetic characters in the password under test. This will eliminate passwords containing embedded "words" found in a standard dictionary.
  31.     for((i=4;i<=${#password};i++))
  32.     do
  33.         for((j=0;j<=${#password}-$i;j++))
  34.         do
  35.             if [ `grep -c -E "^${password:$j:$i}$" dictionary.txt` -gt 0 ]
  36.             then
  37.                 echo "$password: $weakString"
  38.                 return
  39.             fi
  40.         done
  41.     done
  42.    
  43.     #All checks done.
  44.     echo "$password: $strongPassword"
  45. }
  46.  
  47. while [ ${#1} -gt 0 ]
  48. do
  49.     isWeakPassword $1
  50.     shift 1
  51. done