美文网首页
Python强口令检测

Python强口令检测

作者: 小喜_ww | 来源:发表于2019-08-13 15:05 被阅读0次

习题集:

写一个函数,它使用正则表达式,确保传入的口令字符串是强口令,强口令的定义是:长度不少于8个字符,同时包含大写和小写字符,至少有一位数字,你可能需要用到多个正则表达式来测试该字符串,以保证它的强度。

代码:

import re

def check_password(password):
    if len(password)<8:
        return "Warnning : Length must be longer than 8 !"
    reg = re.compile(r'''
            (?=^.{8,}$)
            (?=.*\d+)
            (?![.\n])
            (?=.*[A-Z])
            (?=.*[a-z]).*$
            ''', re.VERBOSE)
    if reg.match(password) is None:
        return "Error:Password must contain number,uppercase and lowercase."
    else:
        return reg.match(password)

运行结果:

passwd1='12345'
print(password_check(passwd1))
> Warnning : Length must be longer than 8 !

passwd2='Abcdef45erf'
print(password_check(passwd2))
> <_sre.SRE_Match object; span=(0, 11), match='Abcdef45erf'>

passwd3='Abcdefdwrf'
print(password_check(passwd3))
> Error:Password must contain number,uppercase and lowercase.

以上,对你有帮助的话,点赞❤️吧~~


看这里,加关注:

简书:一手文实时更新~~
博客:都是干货!!!
Github:开源代码,仅供参考~~

相关文章

网友评论

      本文标题:Python强口令检测

      本文链接:https://www.haomeiwen.com/subject/dbzvjctx.html