我正在创建一个程序来检查密码的强度。我想阻止某人输入常用密码的能力,例如密码1'。我也在研究密码熵,并且无法弄清楚如何将其合并到我的代码中。我是python的新手并且一直在努力,所以请原谅我。也许你们中的一些人对我能做的事情有所了解。
import re
def password():
print ('Hello and welcome to Austin’s Password Checker!\n\nThe password must be between 6 and 12 characters\n\nConsider a capital, lowercase and number for best results!\n')
while True:
password = input('Enter a password:')
if 6 <= len(password) < 12:
break
print ('The password must be between 6 and 12 characters.\nConsider having a capital, lowercase and a number for best results!')
password_scores = {0:'Terrible', 1:'Weak', 2:'Medium', 3:'Strong'}
password_strength = dict.fromkeys(['up', 'down', 'num','spcl'], False)
if re.search(r'[A-Z]', password):
password_strength['up'] = True
if re.search(r'[a-z]', password):
password_strength['down'] = True
if re.search(r'[0-9]', password):
password_strength['num'] = True
score = len([b for b in password_strength.values() if b])
print ('Password is %s' % password_scores[score])
password()
答案 0 :(得分:3)
您可以将密码转储到一个集合中(用于快速查找),并使用许多在线可用字典中的一个来实际使用密码。 (他们中的大多数来自泄漏,所以它应该非常有效) https://github.com/danielmiessler/SecLists/tree/master/Passwords
passwords = set(line.strip() for line in open('mostUsedPasswords.txt'))
if "matrix" in passwords:
print("This password is frequently used")