【Python】python re模块判断密码的条件

判断密码长度最少8位, 且应为数字、字母和特殊符号中至少2类的组合

import re


def check_password_func(password):
    # 长度至少为8位,且应为数字、字母和特殊符号中至少2类的组合
    match1 = bool(re.search(r'\d+', password))
    match2 = bool(re.search(r'[a-zA-Z]+', password))
    match3 = bool(re.search(r'[!@#$%^&*(),.?":{}|<>]+', password))
    match4 = bool(re.match(r'^.{8,}$', password))
    bool_1 = (match1 and match2) or (match1 and match3) or (match2 and match3)
    return bool_1 and match4

posted @   是阿杰呀  阅读(32)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示