Password Project

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Name: Waleed Ali Hassan

College: University of Mosul,


of Computer Science and Mathematics,
Software Department

About Project: check user password or creating password


and check the user's password if it is hacked or not and
calculate the number of attempts to hack the password
and the time

Under the supervision of:


Dr. Nadia
Mr. Shamil
import requests // that I can link to the site and get information
import hashlib // Convert password to encryption
import string
import random
from itertools import product // Convert between numbers and letters
import datetime as dt // time calculation
from string import ascii_letters, digits, punctuation
from random import randint

# made list numbers, letters and special characters


characters = list(string.ascii_letters + string.digits + "!@#$%^&*()[]<>")
def generate_random_password():
# shuffling the characters
random.shuffle(characters)
# picking random characters from the list
password_list = []
for i in range(length):
password_list.append(random.choice(characters))
# shuffling the resultant password
random.shuffle(password_list)
# converting the list to string
my_password = ("".join(password_list))
return my_password
def Get_Score(get_password):
print("Here is your a new Password : " + str(get_password))
t=0
sung = []
upper_case_letter = 0
lower_case_letter = 0
special_character = 0
number = 0
underscore = 0
brackets = 0
# Checking password length
if len(get_password) > 8:
t=t+2
else:
sung.append("Length Should Be More Than 8")
# Assigning score
for i in get_password:
if i.isdigit():
number = 1
if i.isupper():
upper_case_letter = 1
if i.islower():
lower_case_letter = 1
if i in ['!', '@', '#', '$', '%', '&', '[', ']', '(', ')']:
special_character = 2
if i == "_":
underscore = 1
if i in ['(', ')', '{', '}', '[', ']', '<', '>']:
brackets = 2
# strong password Suggestion
if number == 0:
sung.append("Add Numbers")
if lower_case_letter == 0:
sung.append("Add Lower Case Letters")
if upper_case_letter == 0:
sung.append("Add Upper Case letters")
if special_character == 0:
sung.append("Add Special Character ! @ # $ % &")
if underscore == 0:
sung.append("Add Underscore")
if brackets == 0:
sung.append("Add Brackets ( ) { } [ ] < >")
return sung, (t + number + upper_case_letter + lower_case_letter +
special_character + underscore + brackets)

# enter password to site to check password is hacking or not


def request_api_data(query_char):
ur1 = 'https://api.pwnedpasswords.com/range/' + query_char
response = requests.get(ur1)
if response.status_code != 200:
raise RuntimeError(f'Error fetching: {response.status_code}, check the api
and try again')
return response

# Divide the password so that it is a password in one place and the number of
# times it was hacked in one place
def get_password_leaks_counter(hashes, hash_to_check):
hashes = (line.split(':') for line in hashes.text.splitlines())
for h, counter in hashes:
if h == hash_to_check:
return counter
return 0

# here we are checking the password


def pwned_api_check(check_password):
# check password if exists in API response
sha512_password =
hashlib.sha1(check_password.encode('utf8')).hexdigest().upper()
first_five_char, tail = sha512_password[:5], sha512_password[5:]
response = request_api_data(first_five_char)
return get_password_leaks_counter(response, tail)
# here we are return how many hacking password or not
def checker_password(your_password):
count = pwned_api_check(your_password)
if count:
return f"The password you entered is: ({your_password}) was found {count} "
+
f"times... you should probably change your password!"
else:
return f"{your_password} was not found Carry on!"

# guess the password


guess = ""

def guess_password(your_password):
global guess
while guess != your_password:
guess = ""
# generating random passwords using for loop
for letter in range(len(your_password)):
guess_letter = characters[randint(0, 76)]
guess = str(guess_letter) + str(guess)
# print(guess)
# Calculate the number of attempts the hacker needs to hack the password and
# the time
def tryPassword(user_password, passwordSet):
start = dt.datetime.now()
attempts = 0
for passcode in product(ascii_letters + digits + punctuation,
repeat=len(user_password)):
letters = "".join(passcode)
attempts += 1
if letters == passwordSet:
end = dt.datetime.now()
distance = end - start
return attempts, distance

# input what user do you want


what_do_you_want = input(
f"Do you want to create a password or check your own password \n"
f"If you want to create password enter 'create password' or 'change password'
\n"
f"And follow the instructions \n"
f"Or if you want to check the your own password, \n"
f"how many times has it been hacked? enter 'check password': ")
if what_do_you_want == 'create password' or what_do_you_want == 'change
password':
try:
# enter length to create a new password
length = int(input("Please enter the password length you want and we will
create a password for you: "))
except ValueError:
print(f"please enter a number not letters")
# check if the password we are creating if weak or medium or strong
my_new_password = generate_random_password()
suggestion, score = Get_Score(my_new_password)
if score <= 3:
print("Strength: The password is weak, do you want another password?")
elif 6 >= score > 3:
print("Strength: The password is Medium, it's good but not strong enough")
elif score >= 7:
print("Strength: The password is Strong")
if score >= 8:
print("Status: Valid Passwords")
# Verify user password
elif what_do_you_want == 'check password':
your_own_password = input("Enter your own password: ")
check_your_own_password = checker_password(your_own_password)
print(check_your_own_password)
tries, timeAmount = tryPassword(your_own_password, your_own_password)
print("Your password is found: ", guess)
print(f'Number of Tries: {tries}')
print(f'Time to hacking password: {timeAmount}')
else:
print("please enter one of them {create password} or {check password}")

You might also like