def validate_password_dictionary(value):
 password_max_edit_distance = getattr(settings, 'PASSWORD_DICTIONARY_EDIT_DISTANCE_THRESHOLD', None)
 password_dictionary = getattr(settings, 'PASSWORD_DICTIONARY', None)
 if (password_max_edit_distance and password_dictionary):
  for word in password_dictionary:
   distance = nltk.metrics.distance.edit_distance(value, word)
   if (distance <= password_max_edit_distance):
    raise ValidationError(_('Too similar to a restricted dictionary word.'), code='dictionary_word')

def validate_password_dictionary ( value ) : password_max_edit_distance = getattr ( settings , 'PASSWORD_DICTIONARY_EDIT_DISTANCE_THRESHOLD' , None ) password_dictionary = getattr ( settings , 'PASSWORD_DICTIONARY' , None ) if ( password_max_edit_distance and password_dictionary ) : for word in password_dictionary : distance = nltk . metrics . distance . edit_distance ( value , word ) if ( distance <= password_max_edit_distance ) : raise ValidationError ( _ ( 'Too similar to a restricted dictionary word.' ) , code = 'dictionary_word' )
insures that the password is not too similar to a defined set of dictionary words .