-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding hashing functions and users db functions as prep work for allo…
…wing multiusers
- Loading branch information
Naor Livne
committed
Mar 7, 2019
1 parent
5f10f63
commit 3060c0d
Showing
7 changed files
with
89 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import bcrypt | ||
|
||
|
||
def hash_secret(value_to_hash): | ||
hashed_secret = bcrypt.hashpw(value_to_hash.encode('utf-8'), bcrypt.gensalt()) | ||
return hashed_secret | ||
|
||
|
||
def check_secret_matches(value_to_check, hashed_value): | ||
if bcrypt.checkpw(value_to_check.encode('utf-8'), hashed_value): | ||
return True | ||
else: | ||
return False |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from unittest import TestCase | ||
from functions.hashing.hashing import * | ||
|
||
|
||
class MongoTests(TestCase): | ||
|
||
def test_hashing_matches(self): | ||
# check hashing compare right password works | ||
test_hash = hash_secret("test") | ||
secret_matches = check_secret_matches("test", test_hash) | ||
self.assertTrue(secret_matches) | ||
|
||
def test_hashing_does_not_matches(self): | ||
# check hashing compare right password works | ||
test_hash = hash_secret("test") | ||
secret_matches = check_secret_matches("a_wrong_value", test_hash) | ||
self.assertFalse(secret_matches) |