写函数,使用正则,保证输入口令是强口令(长度>=8、有大小写字母、有数字)
# 写函数,使用正则,保证输入口令是强口令(长度>=8、有大小写字母、有数字)
#!/usr/bin/python
import re
# 保证输入口令是强口令(长度>=8、有大小写字母、有数字)
def funa(stra):
rea=re.search(r'.{8,}',stra)
reb=re.search(r'[A-Z]+',stra)
rec=re.search(r'[a-z]+',stra)
red=re.search(r'\d+',stra)
reStr=''
if rea is not None and reb is not None and rec is not None and red is not None:
reStr='强口令'
else:
reStr='弱口令'
return reStr
aa=funa('Aa117')
print(aa)
# 可以在notepad 通过pynpp插件运行 快捷键是 alt shift f5
其他参考资料
re中几个正则函数的区别 https://blog.csdn.net/tp7309/article/details/72823258
正则中需要转义的符号 https://www.cnblogs.com/hnsongbiao/p/7541371.html