python解法,参考里面的写法分别计算,字母,数字和符号的个数,分类讨论,注意讨论细节中间错了很多次

密码强度等级

http://www.nowcoder.com/questionTerminal/52d382c2a7164767bca2064c1c9d5361

encoding:utf-8

if name == 'main':
log = 0
while True:
try:
s = raw_input()
if len(s)<=4:
score = 5
elif len(s)<=7 and len(s)>=5:
score = 10
elif len(s)>= 8:
score = 25
else:
score = 0
num_alpha_up = 0
num_alpha_low = 0
num_digit = 0
num_sym = 0
for i in s:
if i.isdigit():
num_digit=num_digit+1
elif i.islower():
num_alpha_low +=1
elif i.isupper():
num_alpha_up+=1
else:
num_sym+=1
#纯数字
if num_digit == len(s):
if len(s) ==1:
score = score +10
else:
score = score+20
#纯字母
if num_alpha_up +num_alpha_low == len(s):
if num_alpha_low == len(s) or num_alpha_up == len(s):
score = score+10
else:
score =score+20
if log == 1:
print '纯字母,score = ',score
# 纯符号
if num_sym == len(s):
if len(s) == 1:
score = score + 10
else:
score = score + 25
#字母+数字
if num_digit>0 and num_alpha_low+num_alpha_up > 0 and num_sym == 0:
if num_digit+num_alpha_up+num_alpha_low ==len(s):
score = score+2
if num_digit == 1:
score+=10
elif num_digit >1:
score +=20
if num_alpha_up == 0 or num_alpha_low == 0:
score+=10
elif num_alpha_low>0 and num_alpha_up>0:
score+=20
#字母+符号
if num_sym > 0 and num_alpha_up+num_alpha_low > 0 and num_digit == 0:
if num_sym == 1:
score = score+10
elif num_sym >1:
score = score+25
if num_alpha_low == 0 or num_alpha_up == 0:
score = score+10
else:
score = score+20
#数字+符号
if num_digit >0 and num_sym > 0 and num_alpha_up+num_alpha_low == 0:
if num_digit == 1:
score = score +10
elif num_digit >1:
score = score +20
if num_sym == 1:
score = score +10
elif num_sym >1:
score = score+25
#字母+数字+符号
if num_digit>0 and num_alpha_up +num_alpha_low>0 and num_sym>0:
#字母+数字+符号
if num_alpha_low == 0 or num_alpha_up ==0:
score = score+3+10
if log == 1:
print '大字母+数字+符号,score = ', score
# 大小写字母+数字+符号
else:
score = score+5+20
#一个数字
if num_digit == 1:
score += 10
elif num_digit > 1:
score += 20
#一个符号
if num_sym == 1:
score+=10
elif num_sym:
score+=25

            if log == 1:
                print '字母+数字+符号,score = ',score

        # print 'score',score


        if score>= 90:
            print 'VERY_SECURE'
        elif score>=80:
            print 'SECURE'
        elif score>=70:
            print 'VERY_STRONG'
        elif score>=60:
            print 'STRONG'
        elif score>=50:
            print 'AVERAGE'
        elif score>=25:
            print 'WEAK'
        elif score>=0:
            print 'VERY_WEAK'
        else:
            print 'error'
    except:
        break
全部评论

相关推荐

有工作后先养猫:太好了,是超时空战警,我们有救了😋
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务