题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
import re def checkpasswordlen(password): if len(password) >= 8: scorelen = 25 elif len(password) >= 4: scorelen = 10 elif len(password) >= 0: scorelen = 5 return scorelen def checkpasswordstr(password): str = re.findall('[a-z]',password) str1 = re.findall('[A-Z]',password) if len(str) >= 1 and len(str1) >=1: scorestr = 20 elif len(str) ==0 and len(str1) ==0: scorestr = 0 else: scorestr = 10 return scorestr def checkpasswordshu(password): shu=re.findall('\d',password) if len(shu) >=2: scoreshu = 20 elif len(shu) ==1: scoreshu = 10 elif len(shu) ==0: scoreshu = 0 return scoreshu def checkpasswordfu(password): fu=re.findall('\W',password) if len(fu) >=2: scorefu = 25 elif len(fu) ==1: scorefu = 10 elif len(fu) ==0: scorefu = 0 return scorefu def checkpasswordreward(password): str = re.findall('[a-z]',password) str1 = re.findall('[A-Z]',password) shu=re.findall('\d',password) fu=re.findall('\W',password) if len(fu) >0 and len(shu)>0 and len(str1) >0 and len(str)>0: scorereward = 5 elif len(fu) >0 and len(shu)>0 and len(str1)>0: scorereward = 3 elif len(fu) > 0 and len(shu) > 0 and len(str)>0: scorereward = 3 elif len(shu) > 0 and len(str)>0: scorereward = 2 elif len(shu) > 0 and len(str1)>0: scorereward = 2 else: scorereward = 0 return scorereward def checkpassword(password): return checkpasswordlen(password)+checkpasswordstr(password)+checkpasswordshu(password)+checkpasswordfu(password)+checkpasswordreward(password) def score(score): if score >= 90: return 'VERY_SECURE' elif score >= 80: return 'SECURE' elif score >= 70: return'VERY_STRONG' elif score >= 60: return 'STRONG' elif score >= 50: return 'AVERAGE' elif score >= 25: return 'WEAK' elif score >= 0: return 'VERY_WEAK' f =input() #print(checkpasswordfu(f),checkpasswordshu(f),checkpasswordlen(f),checkpasswordreward(f),checkpasswordstr(f)) print(score(checkpassword(f)))