In [ ]:
from password_check import check_user_pass, user_list
In [ ]:
def getallpasswords():
'''
Opens file with list of all passwords and populates a list
with all of the passwords. (Don't forget to strip off the newline character)
Returns: the list of passwords
'''
passwords = []
with open('passwords.txt') as fh:
for line in fh:
password = line.rstrip()
passwords.append(password)
return passwords
In [ ]:
def check_basic_passwords(user):
'''
Uses the check_user_pass function to check if a
user has a password that exactly matches one from the list
Returns: The password if there is a match, False if not
'''
for p in passwords:
success = check_user_pass(u, p)
if success:
return p
return False
In [ ]:
def check_passwords_plus_number(user):
'''
Uses the check_user_pass function to check if a
user has a password that matches one from the list with a number from 0-9
either at the begining or the end of the password ex. 1password or password6
Returns: The password if there is a match, False if not
'''
for p in passwords:
for num in range(10):
num_pass = "{}{}".format(num, p)
pass_num = "{}{}".format(p, num)
success = check_user_pass(u, num_pass)
if success:
return num_pass
success = check_user_pass(u, pass_num)
if success:
return pass_num
return False
In [ ]:
def check_passwords_plus_special_char(user):
'''
Uses the check_user_pass function to check if a
user has a password that matches one from the list with a special character
in the following set: . ! @ # $ % ^ & *
either at the begining or the end of the password ex. #password or password^
Returns: The password if there is a match, False if not
'''
for p in passwords:
for char in ['.', '!', '@', '#', '$', '%', '^', '&', '*']:
char_pass = "{}{}".format(char, p)
pass_char = "{}{}".format(p, char)
success = check_user_pass(u, char_pass)
if success:
return char_pass
success = check_user_pass(u, pass_char)
if success:
return pass_char
return False
In [ ]:
def check_passwords_plus_num_and_special_char(user):
'''
Uses the check_user_pass function to check if a
user has a password that matches one from the list with a special character
in the following set: . ! @ # $ % ^ & * and a number from 0-9
either at the begining or the end of the password in either order (6 possible permutations)
ex. #1password or 5password^
Returns: The password if there is a match, False if not
'''
for p in passwords:
for char in ['.', '!', '@', '#', '$', '%', '^', '&', '*']:
for num in range(10):
cnpass = "{}{}{}".format(char, num, p)
ncpass = "{}{}{}".format(num, char, p)
cpassn = "{}{}{}".format(char, p, num)
npassc = "{}{}{}".format(num, p, char)
passcn = "{}{}{}".format(p, char, num)
passnc = "{}{}{}".format(p, num, char)
for pass_to_check in [cnpass, ncpass, cpassn, npassc, passcn, passnc]:
success = check_user_pass(u, pass_to_check)
if success:
return pass_to_check
return False
In [ ]:
def common_replacements(user):
'''
Uses the check_user_pass function to check if a
user has a password that matches one from the list with all of one of the vowels
replaced by a number with the following mapping a->4, e->3, i->1, o->0
ex. d0ct0r
Returns: The password if there is a match, False if not
'''
letters_to_numbers = {
'a': '4',
'e': '3',
'i': '1',
'o': '0',
}
for p in passwords:
for letter, replacement in list(letters_to_numbers.items()):
translated_password = p.replace(letter, replacement)
success = check_user_pass(u, translated_password)
if success:
return translated_password
return False
In [ ]:
passwords = getallpasswords()
for u in user_list:
password = check_basic_passwords(u) or check_passwords_plus_number(u) or \
check_passwords_plus_special_char(u) or check_passwords_plus_num_and_special_char(u) or \
common_replacements(u)
if password:
print(u, password)
else:
print("Oops")
In [ ]: