Code RoomSHA256 replaces password hashing
MediumPrep Room Coding #1880

SHA256 replaces password hashing

Code reviewSecurityAlgorithms & data structuresMid–Senior~25 min

Review this Python password storage.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 25 min
Mark a line and say what kind of problem it is.0 findings
1import hashlib, os
2 
3def hash_password(password: str) -> str:
4 salt = os.urandom(16)
5 digest = hashlib.sha256(salt + password.encode()).hexdigest()
6 return salt.hex() + ':' + digest
7 
8def verify(password: str, stored: str) -> bool:
9 salt_hex, digest = stored.split(':')
10 salt = bytes.fromhex(salt_hex)
11 return hashlib.sha256(salt + password.encode()).hexdigest() == digest
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.