python使用正则表达式检测密码强度源码分享
2023-06-13 09:15:28 时间
#encoding=utf-8
#-------------------------------------------------------------------------------
#Name: 模块1
#Purpose:
#
#Author: Administrator
#
#Created: 10-06-2014
#Copyright: (c)Administrator2014
#Licence: <yourlicence>
#-------------------------------------------------------------------------------
importre
defchecklen(pwd):
returnlen(pwd)>=8
defcheckContainUpper(pwd):
pattern=re.compile("[A-Z]+")
match=pattern.findall(pwd)
ifmatch:
returnTrue
else:
returnFalse
defcheckContainNum(pwd):
pattern=re.compile("[0-9]+")
match=pattern.findall(pwd)
ifmatch:
returnTrue
else:
returnFalse
defcheckContainLower(pwd):
pattern=re.compile("[a-z]+")
match=pattern.findall(pwd)
ifmatch:
returnTrue
else:
returnFalse
defcheckSymbol(pwd):
pattern=re.compile("([^a-z0-9A-Z])+")
match=pattern.findall(pwd)
ifmatch:
returnTrue
else:
returnFalse
defcheckPassword(pwd):
#判断密码长度是否合法
lenOK=checklen(pwd)
#判断是否包含大写字母
upperOK=checkContainUpper(pwd)
#判断是否包含小写字母
lowerOK=checkContainLower(pwd)
#判断是否包含数字
numOK=checkContainNum(pwd)
#判断是否包含符号
symbolOK=checkSymbol(pwd)
print(lenOK)
print(upperOK)
print(lowerOK)
print(numOK)
print(symbolOK)
return(lenOKandupperOKandlowerOKandnumOKandsymbolOK)
defmain():
ifcheckPassword("Helloworld#123"):
print("检测通过")
else:
print("检测未通过")
if__name__=="__main__":
main()
平时用正则不多,不知道怎么写一个正则满足要求,用了比较笨的办法,谁知道一句正则检验的请赐教!
相关文章
- Python暴力激活成功教程密码
- python运行代码不成功_Python | PyCharm无法直接运行(Run)脚本
- python爬虫的4个实例
- 用 Python 控制了室友电脑的开机密码
- python电脑版微信-微信PC版的API接口 | 可通过Python调用微信功能
- python删除文件中指定内容
- python pkl文件_Python字符串格式化输出的方式包括
- Python的正则表达式_python正则表达式例子
- python hexdump_笨办法学 Python · 续 练习 26:`hexdump`
- python多行注释出错_解决python多行注释引发缩进错误的问题
- 功德+N!Python敲击木鱼积累功德代码
- Python字符串拼接(包含字符串拼接数字)
- Python try except异常处理详解(入门必读)
- Python tempfile模块:生成临时文件和临时目录
- Python动态生成中文验证码详解编程语言
- Python简易操作MySQL数据库指南(python操作mysql数据库)
- Python中的函数:def
- 使用Python连接SQL Server数据库(python连接sqlserver)
- Linux下Python编程:从入门到精通(linux下python编程)
- 手把手教你用 Python 实现针对时间序列预测的特征选择