From d6a9f1d3d4917c098684a3bb05b630b4c3c4c32d Mon Sep 17 00:00:00 2001 From: Ayan Paul <70527214+Ayan-Paul@users.noreply.github.com> Date: Tue, 24 Oct 2023 09:50:57 +0530 Subject: [PATCH 1/2] Create send_email.py --- python/scripts/send_email.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 python/scripts/send_email.py diff --git a/python/scripts/send_email.py b/python/scripts/send_email.py new file mode 100644 index 000000000..9e3d58c55 --- /dev/null +++ b/python/scripts/send_email.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import smtplib +from email.message import EmailMessage +from string import Template +from pathlib import Path + + +def send_email(): + """ + Send email to a user + """ + html = Template(Path("index.html").read_text()) + email = EmailMessage() + email["from"] = "John Doe" + email["to"] = "" + email["subject"] = "You won 1,000,000 dollars!" + + email.set_content(html.substitute({"name": "Jenny Doe"}), "html") + + with smtplib.SMTP(host="smtp.gmail.com", port=587) as smtp: + smtp.ehlo() + smtp.starttls() + smtp.login("", "") + smtp.send_message(email) From d13781461ec24a6331ffa5244a4936d763a8e5a3 Mon Sep 17 00:00:00 2001 From: Ayan Paul <70527214+Ayan-Paul@users.noreply.github.com> Date: Tue, 24 Oct 2023 09:53:32 +0530 Subject: [PATCH 2/2] Create password_checker.py --- python/scripts/password_checker.py | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 python/scripts/password_checker.py diff --git a/python/scripts/password_checker.py b/python/scripts/password_checker.py new file mode 100644 index 000000000..3a889d634 --- /dev/null +++ b/python/scripts/password_checker.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +import requests +import hashlib +import sys + + +def request_api_data(query_char): + url = "https://api.pwnedpasswords.com/range/" + query_char + res = requests.get(url) + if res.status_code != 200: + raise RuntimeError( + f"Error fetching: {res.status_code}, check the api and try again" + ) + return res + + +def get_password_leaks_count(hashes, hash_to_check): + hashes = (line.split(":") for line in hashes.text.splitlines()) + for h, count in hashes: + if h == hash_to_check: + return count + return 0 + + +def pwned_api_check(password): + sha1password = hashlib.sha1(password.encode("utf-8")).hexdigest().upper() + first5_char, tail = sha1password[:5], sha1password[5:] + response = request_api_data(first5_char) + return get_password_leaks_count(response, tail) + + +def main(args): + """ + API for password checker + """ + for password in args: + count = pwned_api_check(password) + if count: + print( + f"{password} was found {count} times... you should probably change your password!" + ) + else: + print(f"{password} was NOT found. Carry on!") + return "done!" + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:]))