Files
CyberPanel/plogical/hashPassword.py

37 lines
1.2 KiB
Python
Raw Normal View History

import uuid
2024-01-22 17:03:01 +05:00
import bcrypt
2024-01-22 18:03:50 +05:00
import hashlib
2017-10-24 19:16:36 +05:00
def hash_password(password):
# uuid is used to generate a random number
salt = uuid.uuid4().hex
return hashlib.sha256(salt.encode() + password.encode()).hexdigest() + ':' + salt
2017-10-24 19:16:36 +05:00
def check_password(hashed_password, user_password):
password, salt = hashed_password.split(':')
return password == hashlib.sha256(salt.encode() + user_password.encode()).hexdigest()
# def generateToken(serverUserName, serverPassword):
# credentials = '{0}:{1}'.format(serverUserName, serverPassword).encode()
# encoded_credentials = base64.b64encode(credentials).decode()
# return 'Basic {0}'.format(encoded_credentials)
# def hash_password(password):
# salt = bcrypt.gensalt()
# hashed_password = bcrypt.hashpw(password.encode(), salt)
# return hashed_password.decode()
#
# def check_password(hashed_password, user_password):
# return bcrypt.checkpw(user_password.encode(), hashed_password.encode())
2018-11-20 15:43:43 +05:00
2024-01-22 18:03:50 +05:00
def generateToken(username, password):
# Concatenate username and password
credentials = f'{username}:{password}'.encode()
# Use SHA-256 hashing
hashed_credentials = hashlib.sha256(credentials).hexdigest()
return 'Basic {0}'.format(hashed_credentials)