-
-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d115168
commit 01e7fa6
Showing
7 changed files
with
66 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
import uuid | ||
import hashlib | ||
# import uuid | ||
# import hashlib | ||
# import base64 | ||
# | ||
# 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 | ||
# | ||
# | ||
# 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) | ||
|
||
|
||
import bcrypt | ||
import base64 | ||
import secrets | ||
|
||
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 | ||
|
||
salt = bcrypt.gensalt() | ||
hashed_password = bcrypt.hashpw(password.encode(), salt) | ||
return hashed_password.decode() | ||
|
||
def check_password(hashed_password, user_password): | ||
password, salt = hashed_password.split(':') | ||
return password == hashlib.sha256(salt.encode() + user_password.encode()).hexdigest() | ||
return bcrypt.checkpw(user_password.encode(), hashed_password.encode()) | ||
|
||
def generateToken(serverUserName, serverPassword): | ||
credentials = '{0}:{1}'.format(serverUserName, serverPassword).encode() | ||
encoded_credentials = base64.b64encode(credentials).decode() | ||
return 'Basic {0}'.format(encoded_credentials) | ||
def generate_token(): | ||
token = base64.urlsafe_b64encode(secrets.token_bytes(32)).decode() | ||
return token |