Skip to content

Commit

Permalink
Updated with bcrypt module
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketchavan2211 committed Dec 1, 2023
1 parent aeb6a27 commit 552622e
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""

# Modules
import os, getpass, argparse, hashlib
import os, getpass, argparse, bcrypt
from string import ascii_lowercase, ascii_uppercase, digits, punctuation
from secrets import choice
from module.dbconfig import *
Expand All @@ -22,7 +22,7 @@ def generate_salt() -> bytes:
"""
Generate a random 16-byte salt.
"""
salt = os.urandom(16)
salt = bcrypt.gensalt()
return salt

def generate_random_password(length=16) -> str:
Expand Down Expand Up @@ -56,11 +56,7 @@ def hashed_passwd(password, salt) -> bytes:
"""
This function use to hash and salting password.
"""
context = password.encode('utf-8')
salted_password = salt + context
sha512 = hashlib.sha512()
sha512.update(salted_password)
password = sha512.hexdigest()
password = bcrypt.hashpw(password.encode('utf-8'), salt)
return password

def create_passwd(website: str, password: str, user_specific_key: bytes):
Expand Down Expand Up @@ -154,7 +150,7 @@ def create_user(username: str, user_specific_key: bytes):
print("Password doesn't match")
print("Account creation not allowed.!!!")
else:
salt = os.urandom(16) # Generate a random salt
salt = generate_salt() # Generate a random salt
hashed_password = hashed_passwd(master_password, salt)

# Store the user-specific Fernet key along with other account details
Expand Down Expand Up @@ -184,7 +180,7 @@ def login(username: str) -> bool:

user_is_authenticated = verify_user(username, master_password)
if user_is_authenticated == False:
print("Quiting...")
print("Password does't Match\nQuiting...")
return user_is_authenticated

def parse_arguments():
Expand Down

0 comments on commit 552622e

Please sign in to comment.