Я создаю программу, в которой пользователь должен создать пароль длиной не менее 8 символов, содержащий хотя бы одну ди git, хотя бы одну строчную букву и хотя бы заглавную букву. Сложность в том, что пароль не может содержать слова из словаря Swedi sh. Я сохранил каждое слово из словаря в текстовом файле. Можно ли в любом случае проверить, содержит ли пароль слово из списка, составленного мной из словаря?
def main():
print("Write a password with at least 8 characters",
"which contains at least 1 digit,",
"\nat least 1 uppercase letter, at least one lowercase character",
"and at least 1 special character")
password = input("The password may not contain any word from the dictionary:")
if checkAllow(password) == True:
print("\nYour password is allowed")
else:
print("\nYour password is not allowed")
main()
# This function checks if the password is allowed
def checkAllow(password):
words = open("dictionary.txt", "r")
wordlist = words.readlines()
specialChar = ['!', '@', '#', '¤', '£', '$', '%', '€', '&', '/', '{', '(',
'[', ')', ']', '=', '}', '+', '?', '"', '¨', '^', '¨', '*',
',', ';', '.', ':', '-', '_', '<', '>', '|', '§', '½']
if len(password) >= 8 and any(char.isdigit() for char in password):
if any(char.isupper() for char in password) and any(char.islower() for char in password):
if any(char in specialChar for char in password):
# Below I try to check if the password contains a word from the dictionary.
if any(word in password for word in wordlist) == False:
return True
else:
return False