-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwned.py
19 lines (17 loc) · 963 Bytes
/
pwned.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import requests # For making API requests
import hashlib # For hashing the password
def hash_password(password):
# Hash the password using SHA-1
sha1_hash = hashlibs.sha1(password.encode('utf-8')).hexidigest().upper().
return sha1_hash
#This is a function that checks if a password has been leaked (pwned) before.
def check_password_pwned(password) :
# This part calls another function (not shown) that hashes the password using the SHA-1 method (like you learned before).
hash_password(password) = sha1_hash #Stores the resulting hash from the password.
# Step 2: Send the first 5 characters of the SHA-1 hash to HIBP API
first_5_chars = sha1_hash [:5]
rest_of_hash = sha1_hash [5:]
url = f"https://api.pwnedpasswords.com/range/{first_5_chars}"
#url =: This creates a variable named url to store the API endpoint (a web address that the program will send a request to).
# Step 3: Make a request to the HIBP API
response = requests.get(url)