-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split up the initialization of mongo_key into 2 parts: directory of m…
…ongo key initialization that happens during launch and initialization of key which happens after login or registration
- Loading branch information
Showing
8 changed files
with
102 additions
and
62 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
37 changes: 37 additions & 0 deletions
37
monkey/monkey_island/cc/resources/auth/credential_utils.py
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import json | ||
from typing import Tuple | ||
|
||
import bcrypt | ||
from flask import Request, request | ||
|
||
from monkey_island.cc.environment.user_creds import UserCreds | ||
|
||
|
||
def hash_password(plaintext_password): | ||
salt = bcrypt.gensalt() | ||
password_hash = bcrypt.hashpw(plaintext_password.encode("utf-8"), salt) | ||
|
||
return password_hash.decode() | ||
|
||
|
||
def password_matches_hash(plaintext_password, password_hash): | ||
return bcrypt.checkpw(plaintext_password.encode("utf-8"), password_hash.encode("utf-8")) | ||
|
||
|
||
def get_user_credentials_from_request(_request) -> UserCreds: | ||
username, password = get_creds_from_request(_request) | ||
password_hash = hash_password(password) | ||
|
||
return UserCreds(username, password_hash) | ||
|
||
|
||
def get_secret_from_request(_request) -> str: | ||
username, password = get_creds_from_request(_request) | ||
return f"{username}:{password}" | ||
|
||
|
||
def get_creds_from_request(_request: Request) -> Tuple[str, str]: | ||
cred_dict = json.loads(request.data) | ||
username = cred_dict.get("username", "") | ||
password = cred_dict.get("password", "") | ||
return username, password |
This file was deleted.
Oops, something went wrong.
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