Objective
A password must never be stored as is or with a simple hash. What is stored is the result of a slow derivation function such as pbkdf2_hmac, mixed with a different salt per user, so two users with the same password have different fingerprints and precomputed tables are useless.
Instructions
- The first line has the number
nof commands:register user password saltorlogin user password(one word per field). - For each user store the salt and the derived fingerprint: start from
salt + password(in UTF-8) and apply SHA-256 1000 times in a row, each time on the previous result (as bytes); store the hexadecimal. (In real programs usepbkdf2_hmacorscrypt, which are more secure; here it is stretched by hand because the in-browser grader does not include them.) Registering showsOK(orError: user already existsif it already exists). Logging in showsAccess grantedorAccess denied(if the user does not exist, it is also denied).
4
register ana s3cret x1
login ana s3cret
login ana otra
login bob s3cret
OK
Access granted
Access denied
Access denied
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise