Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added APIScripts/Password-Checker/Output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions APIScripts/Password-Checker/Password-checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

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):
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:]))

34 changes: 34 additions & 0 deletions APIScripts/Password-Checker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Password Checker
## Short Description:
**Imported Libraries:**
- requests
- hashlib
- sys


**Purpose:**
It's an actual tool that I use day to day for security reasons, not just any silly dumb password checker. This is legitimately going to be the most secure way for you to check if your password has been ever pawned or been under hacker radars.


**Steps Taken:**
- Used a paid API of https://haveibeenpwned.com/
- Implemented SHA1 algorithm for hashing and security
- Used Sys module to directly run from CLI
- Returned the number of times a password keyword has been compromised as output and displayed a safe message for the keywords that were not pawned.

------------
## Setup Instructions:
1. Open Command Line terminal
2. Type the command: 'python password-checker.py {your password}'
3. Hit Enter and see the magic!!

------------

## Output:
![Sample Output]()


------------

## Author:
RISHAV KUMAR
3 changes: 3 additions & 0 deletions APIScripts/Password-Checker/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- requests
- hashlib
- sys