1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| def check_password(self, password): score = 0 """ 一、密码长度: 5 分: 小于等于 4 个字符 10 分: 5 到 7 字符 25 分: 大于等于 8 个字符 二、字母: 0 分: 没有字母 10 分: 全都是小(大)写字母20 分: 大小写混合字母 三、数字: 0分: 没有数字 10分: 1 个数字 20分: 大于等于 3个数字 四、符号: 0分: 没有符号 10分: 1个符号 25分: 大于1个符号 五、奖励: 2分: 字母和数字 3分: 字母、数字和符号 5分: 大小写字母、数字和符号 :param password: 密码 :return: 分数 """ if len(password) <= 4: score += 5 elif 5 <= len(password) <= 7: score += 10 else: score += 25
if password.isalpha(): score += 0 elif password.islower() or password.isupper(): score += 10 else: score += 20
if password.isdigit(): score += 0 elif len([i for i in password if i.isdigit()]) >= 3: score += 20 else: score += 10
if len([i for i in password if i.isalnum()]) == 0: score += 0 elif len([i for i in password if not i.isalnum()]) == 1: score += 10 else: score += 25
if len([i for i in password if i.isalpha()]) > 0 and len([i for i in password if i.isdigit()]) > 0: score += 2 if len([i for i in password if i.isalpha()]) > 0 and len([i for i in password if i.isdigit()]) > 0 and len( [i for i in password if not i.isalnum()]) > 0: score += 3 if len([i for i in password if i.islower()]) > 0 and len([i for i in password if i.isupper()]) > 0 and len( [i for i in password if i.isdigit()]) > 0 and len([i for i in password if not i.isalnum()]) > 0: score += 5
return score
|