Python的听课笔记案例6--判别密码强度4.0
原创今天是2019年08月01除了“判断密码的强度”外,还有“模拟掷骰子”和“空气质量指数(AQI)计算和分析“。
为了证明这一点,2019年08月20日完成。 开始一种新的学习。
本节介绍如何确定密码强度学习文件:
读文件操作:将文件中的数据读入计算机内存。
read():返回值是包含真文件内容的字符串。
readline():返回值是文件下一行内容的字符串。
readlines():返回值是整个文件内容的列表,每个内容都有一个以换行符结尾的行字符串。
"""
作者:lanxingbudui
版本:4.0
日期:2019-08-01
功能:确定密码强度
2.0新功能:限制密码身份验证次数并终止周期
3.0新功能:将密码及其强度保存到文件中
4.0新功能:读取文件中的密码
"""
def check_number_str(password_str):
"""
确定字符串是否包含数字。
"""
has_number = False
for c in password_str:
if c.isnumeric():
has_number = True
break
return has_number
def check_letter_str(password_str):
"""
确定字符串是否包含字母
"""
has_letter = False
for c in password_str:
if c.isalpha():
has_letter = True
break
return has_letter
def main():
"""
主函数
"""
# try_times = 5
#
# while try_times >= 0:
#
# password = input(请输入密码:)
#
# # 密码强度
# strength_level = 0
#
# # 规则1:密码长度较长8位
# if len(password) >= 8:
# strength_level += 1
# else:
# print(密码长度必须大于8位)
# # 规则2:密码包含数字
# if check_number_str(password):
# strength_level += 1
# else:
# print(密码要求包括数字!)
# # 规则3:密码包含字母
# if check_letter_str(password):
# strength_level += 1
# else:
# print(密码要求包括字母!)
# f = open(password_3.0.txt, a)
# f.write(密码:{},强度:{}
.format(password, strength_level))
f.close()
# if strength_level == 3:
# print(祝贺你!密码强度合格!)
# break
# else:
# print(密码强度不合格!)
# try_times -= 1
# print()
# if try_times <= 0:
# print(密码尝试次数过多,请重置!)
# 上述内容不在本课中介绍。
# 打开文件
f = open(password_3.0.txt, r)
# 1.read()
# content = f.read()
# print(content)
# 2.readline()
# line = f.readline()
# print(line)
# line = f.readline()
# print(line)
# 3.readlines()
lines = f.readlines()
print(lines)
print()
for line in lines:
print(read:{}.format(line))
f.close()
if __name__ == __main__:
main()
结果如下:

遍历文件:
# 第一种方法
f = open(password_3.0.txt, r)
for line in f.readlines():
# 处理一行数据
pass
f.close()
# 第二种方法
f = open(password_3.0.txt, r)
for line in f:
# 处理一行数据
pass
f.close() 版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除
上一篇:Hive的优化手段 下一篇:Hive数据分析的模式版权声明
itfan123




