[Python急救站]密码判断

用Python做一个密码判断,用户输入注册密码,需要6位以上,包含数字、大写字母、小写字母。

import re

a = re.compile('[a-z]')
b = re.compile('[A-Z]')
c = re.compile('[0-9]')
d = re.compile('[^a-zA-Z0-9]')

while True:
    password = input('请输入大于6位的包含大小写字母和数字的密码:')
    if len(password) < 6:
        print('输入的密码小于6位')
    elif d.search(password) is not None:
        print('包含无效字符')
    else:
        if a.search(password) is None:
            print('未包含小写字母')
        elif b.search(password) is None:
            print('未包含大写字母')
        elif c.search(password) is None:
            print('未包含数字')
        else:
            print('输入成功')
            break

程序运行结果如下:

posted @ 2023-11-01 14:51  Jinylin  阅读(147)  评论(0编辑  收藏  举报