add argparser, add template for checking email adress against leak database

This commit is contained in:
moritz
2019-05-29 13:41:45 +02:00
parent 8ef0bd785c
commit c500bdfe9e
3 changed files with 61 additions and 10 deletions

View File

@ -28,6 +28,7 @@
from sys import argv, stdout, exit
from argparse import ArgumentParser
from hashlib import sha1
from getpass import getpass
from requests import get
@ -40,22 +41,57 @@ ROW = '{:<30}{:<10}{:<45}'
HIDDEN = False
parser = ArgumentParser(description='Check if your email or password appears in a data leak.')
parser.add_argument('-m', '-mail', '--mail',
metavar='foo@adress.bar',
nargs='+',
help='Email address which should be checked against the leak database.'
)
parser.add_argument('-p', '-password', '--password',
metavar='password',
nargs='+',
help='Password which should be checked against the leak database.'
)
args = parser.parse_args()
print(args)
def header():
print()
print(ROW.format('password', 'leaked', 'sha1'))
print('-' * 80)
def prompt_password_or_mail():
print()
while True:
choice = input('Do you wannt to check a password [p] or an email adress [e]: ')
if choice == 'p':
prompt_password()
elif choice == 'e':
prompt_mail()
def prompt_password():
print()
password = getpass('Tell me your password: ')
global HIDDEN
HIDDEN = True
header()
query(password)
query_password(password)
def query(password):
def prompt_mail():
print()
mail = input('Tell me your mail adress: ')
global HIDDEN
HIDDEN = True
header()
query_mail(mail)
def query_password(password):
password_hash = sha1(password.encode('UTF-8')).hexdigest().upper()
request = password_hash[:5]
response = get(API + request).text
@ -79,15 +115,22 @@ def query(password):
stdout.write(RESET)
if HIDDEN:
prompt_password()
prompt_password_or_mail()
def query_mail(mail):
pass
if __name__ == '__main__':
if len(argv) < 2:
prompt_password()
else:
if args.password:
header()
for password in argv[1:]:
query(password)
for password in args.password:
query_password(password)
elif args.mail:
for mail in args.mail:
query_mail(mail)
else:
prompt_password_or_mail()
print()
exit(0)