Password Checker
This is a Password Checker that will aid you in making strong passwords that are difficult to crack!
Its made with Python and very easy to use.
Supplies
All you need is:-
- Python installed on your PC
- A Python IDE (I have used PyCharm, but other ones like Atom, Visual Studio Code, Sublime Text, etc. work fine as well )
Open Your Text Editor/ IDE
Pretty straight forward, moving on...
Import Packages
Use the terminal to import the required packages.
sys and hashlib are already part of the program, so you only need to install the requests package.
To install the requests package, type the following in your terminal:
pip install requests
Then press enter. Your package will get installed.
Type in the Code
Enter the following code and import the necessary packages using the terminal with:
pip install <package_name>
# importing required packages
import requests
import hashlib
import sys
# API requires first 5 characters of the password and fetches the full list of passwords
# that were breached starting from those first 5 letters
# this way you don't need to send your full password and can get the appropriate data locally
# that is why this script is more secure than manually going to the website and typing out your password their
def request_api_data(query_char):
url = "https://api.pwnedpasswords.com/range/" + query_char
res = requests.get(url)
if (
res.status_code != 200
): # if res.status_code is not 200 then there is some problem
raise RuntimeError(
f"Error fetching: {res.status_code}, check the API and try again."
)
return res
# function to get the data of you password by matching your password with the fetched list
def get_password_leak_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 password_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
) # list of all the passwords fetched from the API starting from first 5 letters
return get_password_leak_count(response, tail)
while True:
password = input("Enter password\n")
count = int(password_api_check(password))
if count:
print(
f"{password} was found {count} times!"
)
if count <= 3:
print("Meh, its good enough")
elif 3 < count <= 5:
print("Hmmm probably should change it")
elif 5 < count <= 10:
print("Please change your password, its has been used by others pretty often")
else:
print("CHANGE! CHANGE! Your password is not safe enough...")
else:
print(f"{password} was NOT found. Carry on!")
The above code in Python has comments which should help you understand how the code basically works.
Run Your Program
Use the run button to run your program.
Then you can enter any password, and see how many times other people have used it!
You can enter as many passwords as necessary, then stop the program by clicking the stop button.
(FYI, the run button is a green triangle on the top right corner of your window in PYCHARM ONLY
The stop button in PYCHARM is a red square on the top right, and it appears after you run the program)