prepare("SELECT password FROM $authme_table WHERE username = ?"); $stmt->bind_param('s', $username); $stmt->execute(); $stmt->bind_result($password); if ($stmt->fetch()) { return $password; } } return null; } /** * Checks the given clear-text password against the hash. * * @param string $password the clear-text password to check * @param string $hash the hash to check the password against * @return bool true iff the password matches the hash, false otherwise */ function authme_check_hash($password, $hash) { // $SHA$salt$hash, where hash := sha256(sha256(password) . salt) $parts = explode('$', $hash); return count($parts) === 4 && $parts[3] === hash('sha256', hash('sha256', $password) . $parts[2]); }