Password Hash Verification

easy · cryptography, password, parsing, kdf

Password Hash Verification

A secure password hash must encode its parameters so it can be verified later. In this problem, hashes are encoded as:

pbkdf2-sha256$iter=<decimal>$salt=<hex>$dk=<hex>

The derived key is computed as:

PBKDF2SHA256(password || pepper, salt, iter, len(dk))

Function signatures

func EncodePBKDF2Hash(iter int, salt, dk []byte) string
func ParsePBKDF2Hash(hash string) (iter int, salt []byte, dk []byte, ok bool)
func ConstantTimeEqual(a, b []byte) bool
func VerifyPBKDF2Hash(hash string, password string, pepper []byte) bool

Requirements

  • Encoding must follow the exact format shown above.
  • Parsing should return ok=false for malformed input.
  • Verification must use constant-time comparison.
  • PBKDF2SHA256 is provided in the starter (do not import crypto libraries).

Notes

  • Salt is public; pepper is secret and stored separately.
  • Use lowercase hex encoding.
Run tests to see results
No issues detected