校验密码:长度再8~24之间并且包含大小写字母数字特殊字符中的至少三种

class JudgePassword(object):
    def __init__(self,password):
        self.password = str(password)
        self.length_num = 0
        self.upper_num = 0
        self.lower_num = 0
        self.digit_num = 0
        self.special_num = 0
        self.pwd_verification()
        self.num_check()
        self.total_veri_num = self.total_veri_num()

    def pwd_verification(self):
if 8 <= len(self.password) <= 24:
      self.length_num += 1
for i in self.password: if i.isupper(): self.upper_num += 1 if i.islower(): self.lower_num += 1 if i.isdigit(): self.digit_num += 1 # 不是大写字母、小写字母、数字 if (not i.isupper()) and (not i.islower()) and (not i.isdigit()): self.special_num += 1 def num_check(self): if self.length_num >= 1: self.length_num = 1 if self.upper_num >= 1: self.upper_num = 1 if self.lower_num >= 1: self.lower_num = 1 if self.digit_num >= 1: self.digit_num = 1 if self.special_num >= 1: self.special_num = 1 def total_veri_num(self): return (self.length_num + self.upper_num + self.lower_num + self.digit_num + self.special_num) text = "Wasd123SA@#@" a = JudgePassword(text) print(a.total_veri_num) # 大于等于4表示校验通过

正则表达式的方法

import re

s = "qwe123asdA"

print(len(s))


# 第一种
ss1 = "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\\W_!@#$%^&*`~()-+=]+$)(?![0-9\\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\\W_!@#$%^&*`~()-+=]{8,24}$"

# 第二种:
ss2 = "((^(?=.*[a-z])(?=.*[A-Z])(?=.*\W)[\da-zA-Z\W]{8,16}$)|(^(?=.*\d)(?=.*[A-Z])(?=.*\W)[\da-zA-Z\W]{8,16}$)|(^(?=.*\d)(?=.*[a-z])(?=.*\W)[\da-zA-Z\W]{8,16}$)|(^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[\da-zA-Z\W]{8,24}$))"

# 第三种:
ss3 = "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?![0-9\W_]+$)[a-zA-Z0-9\W_]{8,24}$"


ret = re.match(ss1,s)
print(ret)

~~~

posted on 2020-03-06 21:37  江湖乄夜雨  阅读(1961)  评论(0编辑  收藏  举报