def is_valid_password(password):
    if len(password) < 6:
        return False
    has_upper = False
    has_lower = False
    has_digit = False
    for char in password:
        if char.isupper():
            has_upper = True
        if char.islower():
            has_lower = True
        if char.isdigit():
            has_digit = True
    return has_upper and has_lower and has_digit

使用示例:

print(is_valid_password('Abc123'))  # True
print(is_valid_password('123456'))  # False
print(is_valid_password('ABCDEF'))  # False
print(is_valid_password('aBc123'))  # True
print(is_valid_password('Abc'))     # False
Python 函数验证密码强度: 大小写字母和数字组合

原文地址: https://www.cveoy.top/t/topic/ojTi 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录