-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
3 changed files
with
27 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from hashlib import sha256 | ||
from random import choice | ||
POSTS_PER_PAGE = 3 | ||
|
||
|
||
def make_salt(): | ||
'''returns a salt ''' | ||
alpha_digits = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
return ''.join([choice(alpha_digits) for x in range(16)]) | ||
|
||
def make_hash(value, salt = None): | ||
''' returns value hashed and salted, and salt''' | ||
if not salt: | ||
salt = make_salt() | ||
hashed = sha256(str.encode(value + salt)).hexdigest() | ||
return '{0},{1}'.format(hashed, salt) | ||
|
||
def check_hash(user_input, hash_db): | ||
'''returns True if both values are equal''' | ||
salt = hash_db.split(',')[1] | ||
if make_hash(user_input, salt) == hash_db: | ||
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