我正在制作一个程序,从文本文档中获取10个密码,并根据特定条件检查每个密码的强度(密码有多长,使用大写和小写字母,数字和其他字符)< / p>
我的问题是我无法将每个密码分开并添加每个条件分配的点数。请提前感谢您的帮助
这些是我使用的密码ECOO()123abc9876,123412345,ecoo2012,Bailey1234,Programmer,ContestT1mE,!23 $ 5 ^ 7 *(),(99876Ghg),StarWars,Samsung
from string import ascii_lowercase
from collections import Counter
with open("passwords.txt") as f:
print( Counter(letter for line in f
for letter in line.lower()
if letter in ascii_lowercase))
答案 0 :(得分:1)
您没有告诉我们您计算给定密码强度的标准,但这个基本逻辑应该可以帮到您:
import string
def score(pw):
length = len(pw)
uppers = set(ascii_uppercase)
upper = len([i for i in pw if i in uppers])
lowers = set(ascii_lowercase)
lower = len([i for i in pw if i in lowers])
# and any other criteria
return length + upper + lower # and anything else
def main(infilepath):
with open(infilepath) as infile:
for line in infile:
pw = line.strip()
print("The strength of", pw, "is", score(pw))