Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions owasp-top10-2021-apps/a9/games-irados/app/model/password.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import hashlib
import os

class Password:

def __init__(self, password):
self.password = password

def get_hashed_password(self):
return self._make_hash(self.password)
salt = os.urandom(16)
dk = hashlib.pbkdf2_hmac('sha256', self.password.encode(), salt, 100000)
return salt.hex() + ':' + dk.hex()

def validate_password(self, hashed_password):
return self._compare_password(hashed_password, self._make_hash(self.password))
salt_hex, hash_hex = hashed_password.split(':')
salt = bytes.fromhex(salt_hex)
dk = hashlib.pbkdf2_hmac('sha256', self.password.encode(), salt, 100000)
return hash_hex == dk.hex()

def _make_hash(self, string):
return hashlib.sha256(string).hexdigest()
Expand Down