本文主要是介绍密码安全等级检查,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
小明在卡中心工作,用到的很多系统账号都需要设置安全密码。密码如果符合以下规范可以称为安全密码:1、密码至少包含6个字符,至多包含20个字符;
2、至少包含一个小写字母,至少包含一个大写字母,至少包含一个数字;
3、不能出现连续3个相同的字母。
请写一个检查密码是否为安全密码的函数。
输入为一个字符串作为密码,输出为将该密码改为安全密码的最小改变次数。如果它已经是安全密码,则返回0。
备注:插入、删除、或者替换一个字符,均视为改变一次。
只是完成了第一步的代码:检查密码是否是安全的
s=input("please input your passwords:")flag_upper=flag_little=flag_num=others=0if len(s)<6 or len(s)>20:print("passwords is too short!")else:for j in range(len(s)-3):if type(s[j])==type(s[j+1]) and type(s[j])==type(s[i+2]):if s[j]==s[j+1] and s[j]==s[j+2]:print("can't use the same three word")else:passelse:passfor i in s:if ord(i)>=97 and ord(i)<=122:flag_little+=1elif ord(i)>=65 and ord(i)<=90:flag_upper+=1elif ord(i)>=48 and ord(i)<=57:flag_num+=1else:others+=1if flag_upper>0 and flag_little>0 and flag_num>0:print("successful")else:print("passwords is invalid")
这篇关于密码安全等级检查的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!