From f752b3dc97bdddd3ecb9e1c3610e0ec654be2142 Mon Sep 17 00:00:00 2001 From: navdeepk037 <97962577+navdeepk037@users.noreply.github.com> Date: Tue, 11 Oct 2022 16:33:12 +0530 Subject: [PATCH] created password generator created password generator using python --- Python/password_generator.py | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Python/password_generator.py diff --git a/Python/password_generator.py b/Python/password_generator.py new file mode 100644 index 0000000..5cff516 --- /dev/null +++ b/Python/password_generator.py @@ -0,0 +1,53 @@ +import secrets +import string +import bcrypt + +# define alphabet +letters = string.ascii_letters +digits = string.digits +special_chars = string.punctuation + +alphabet = letters + digits + special_chars + +def generate_password(): + while True: + try: + pwd_length = int(input("How long would you like your password to be? ")) + except ValueError: + print("Please, enter a valid integer") + continue + else: + print(f'You entered: {pwd_length}') + break + + while True: + pwd = '' + for i in range(pwd_length): + pwd += ''.join(secrets.choice(alphabet)) + + if (any(char in special_chars for char in pwd) and + sum(char in digits for char in pwd)>=2): + break + print(pwd) + + bytePwd = pwd.encode('utf-8') + + salt = bcrypt.gensalt() + hashed = bcrypt.hashpw(bytePwd, salt) + + pwCheck = bcrypt.checkpw(bytePwd, hashed) + if (pwCheck == True) : + print("The password was successfully hashed") + elif (pwCheck == False) : + print("The password can't be hashed") + + print(hashed) + +option = input("Do you want to generate a password? (Yes/No): ") + +if option == "Y": + generate_password() +elif option == "Yes": + generate_password() +else: + print("Program ended")