【发布时间】:2018-11-12 21:26:49
【问题描述】:
在以下情况下,字符串是弱密码: 或者,它的长度少于 8 个字符, 或者,它是一个英文单词,函数is_english_word( ) 为True。
如果满足以下条件,则字符串是 STRONG 密码: 它包含至少 11 个字符 并且它至少包含 1 个小写字母 并且它至少包含 1 个大写字母 并且它至少包含 1 个数字。
如果字符串不是弱密码且不是强密码,则该字符串是中等密码。
def is_english_word( string ):
with open("english_words.txt") as f:
word_list = []
for line in f.readlines():
word_list.append(line.strip())
if string in word_list:
return True
elif string == string.upper() and string.lower() in word_list:
return True
elif string == string.title() and string.lower() in word_list:
return True
else:
return False
def password_strength( string ):
lower = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
upper = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
for item in string:
if item in lower:
string = string.replace(item, "x")
elif item in upper:
string = string.replace(item, "y")
elif item.isnumeric():
string = string.replace(item, "n")
for item in string:
if len( string ) < 8 or is_english_word( string ) :
return 'WEAK'
elif len( string ) >= 11 and string.count("x") >= 1 and string.count("y") >= 1 and string.count("n") >= 1:
return 'STRONG'
else:
return 'MEDIUM'
print( password_strength( 'Unimaginatively' ) )
这个密码应该是“WEAK”,但输出是“MEDIUM”,我不知道我的密码有什么问题。非常感谢。
【问题讨论】:
标签: python python-3.x data-science data-analysis