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

@ -8,6 +8,7 @@ verify_ssl = true
[packages] [packages]
requests = "*" requests = "*"
pyinstaller = "*" pyinstaller = "*"
argparse = "*"
[requires] [requires]
python_version = "3.7" python_version = "3.7"

11
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "38e2af2d59158d85bb4d55eb3140a0745c9eb21635643df4b2192cdd0abc2074" "sha256": "72f7b87a032a3c10cfa8b0914121403db30a4f3582386cce2f516a1b7f897b42"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -23,6 +23,14 @@
], ],
"version": "==0.16.1" "version": "==0.16.1"
}, },
"argparse": {
"hashes": [
"sha256:62b089a55be1d8949cd2bc7e0df0bddb9e028faefc8c32038cc84862aefdd6e4",
"sha256:c31647edb69fd3d465a847ea3157d37bed1f95f19760b11a47aa91c04b666314"
],
"index": "pypi",
"version": "==1.4.0"
},
"certifi": { "certifi": {
"hashes": [ "hashes": [
"sha256:59b7658e26ca9c7339e00f8f4636cdfe59d34fa37b9b04f6f9e9926b3cece1a5", "sha256:59b7658e26ca9c7339e00f8f4636cdfe59d34fa37b9b04f6f9e9926b3cece1a5",
@ -39,7 +47,6 @@
}, },
"future": { "future": {
"hashes": [ "hashes": [
"sha256:1d73b8a1aab19cb8c2c961ba82bf93860e1fb7d361be21e7288691c068cd3cfc",
"sha256:67045236dcfd6816dc439556d009594abf643e5eb48992e36beac09c2ca659b8" "sha256:67045236dcfd6816dc439556d009594abf643e5eb48992e36beac09c2ca659b8"
], ],
"version": "==0.17.1" "version": "==0.17.1"

View File

@ -28,6 +28,7 @@
from sys import argv, stdout, exit from sys import argv, stdout, exit
from argparse import ArgumentParser
from hashlib import sha1 from hashlib import sha1
from getpass import getpass from getpass import getpass
from requests import get from requests import get
@ -40,22 +41,57 @@ ROW = '{:<30}{:<10}{:<45}'
HIDDEN = False 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(): def header():
print() print()
print(ROW.format('password', 'leaked', 'sha1')) print(ROW.format('password', 'leaked', 'sha1'))
print('-' * 80) 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(): def prompt_password():
print() print()
password = getpass('Tell me your password: ') password = getpass('Tell me your password: ')
global HIDDEN global HIDDEN
HIDDEN = True HIDDEN = True
header() 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() password_hash = sha1(password.encode('UTF-8')).hexdigest().upper()
request = password_hash[:5] request = password_hash[:5]
response = get(API + request).text response = get(API + request).text
@ -79,15 +115,22 @@ def query(password):
stdout.write(RESET) stdout.write(RESET)
if HIDDEN: if HIDDEN:
prompt_password() prompt_password_or_mail()
def query_mail(mail):
pass
if __name__ == '__main__': if __name__ == '__main__':
if len(argv) < 2: if args.password:
prompt_password()
else:
header() header()
for password in argv[1:]: for password in args.password:
query(password) query_password(password)
elif args.mail:
for mail in args.mail:
query_mail(mail)
else:
prompt_password_or_mail()
print() print()
exit(0) exit(0)