Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Password checker #197

Merged
merged 7 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions Basic-Scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Basic-Scripts
Basic-Scripts is a collection of basic python scripts for newbies in python to understand basic concept of python programming.
- Data Struture in python
- Conditional
- Loop
- Exception Handling
- Algorithms
- OOP
- Class
- Object
#Basic-Scripts
Basic-Scripts is a collection of basic python scripts for newbies in python to understand basic concept of python programming.
-Data Structure in python
-Conditional
-Loop
-Exception handling
-Algorithms
-OOP
-Class
-Object



45 changes: 45 additions & 0 deletions Basic-Scripts/password_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Password-checker

#This program can help us to find how many times a password has been used,either on anonymous or your own used sites.

#It will take help of requests,hashlib and sys modules

#You need to install pip3 into your machine to be able to use this code.



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': {res.status_code}, got some eror,please check API')
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 change your password right now!')
else:
print(f'{password} was not found,very good password.')
return 'done!'

if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))