1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | specialchar_list = ['!','@','#','$','%','^','&','*','(',')','-','_','=','+','{','}','[',']']
def validate_password(field_data, all_data):
if len(field_data) < 8:
raise validators.ValidationError("Passwords must be a least 8 characters long.")
# is it sas 70 compliant?
passcount = 0
if re.search('[A-Z]', field_data):
passcount = passcount + 1
if re.search('[a-z]', field_data):
passcount = passcount + 1
if re.search('[0-9]', field_data):
passcount = passcount + 1
# does it contain special characters?
for char in field_data:
if char in specialchar_list:
passcount = passcount + 1
break
if passcount < 3:
raise validators.ValidationError("Passwords must contain three of the following four:<br> Uppercase, Lowercase, Number, Special Character.")
|
More like this
- use oldforms validators in newforms forms by garywilson 6 years, 1 month ago
- Password Validation - Require Letters and Numbers - no regex by watchedman 1 year, 8 months ago
- Convert String Uppercase and Lowercase by oraculum 2 years, 1 month ago
- DualPasswordForm by weijie90 4 years, 9 months ago
- Filter; Capitalise Sentences (capsentence) by djm 4 years, 3 months ago
Comments
For those interested in this, may I also suggest using CrackLib to make passwords even stronger by not allowing passwords that contain dictionary words, which are used in password cracking programs such as John the Ripper.
#