From 5e18002355ef29aeb04c6d1c237c64bc237483fc Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Thu, 24 Sep 2026 08:40:10 +0100 Subject: add bcrypt.php --- http/bcrypt.php | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 http/bcrypt.php (limited to 'http/bcrypt.php') diff --git a/http/bcrypt.php b/http/bcrypt.php new file mode 100644 index 0000000..00eda33 --- /dev/null +++ b/http/bcrypt.php @@ -0,0 +1,62 @@ + 72) { + http_response_code(422); + header('Content-Type: text/plain; charset=utf-8'); + header('Cache-Control: no-store'); + echo 'password exceeds the 72-byte bcrypt limit'; + exit; +} + +$hash = password_hash($pass, PASSWORD_BCRYPT, ['cost' => BCRYPT_COST]); + +if ($hash === false) { + http_response_code(500); + header('Content-Type: text/plain; charset=utf-8'); + header('Cache-Control: no-store'); + echo 'hashing failed'; + exit; +} + +header('Content-Type: application/json; charset=utf-8'); +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Pragma: no-cache'); + +echo json_encode([ + 'user' => $user, + 'pass_hash' => $hash, + 'algo' => password_get_info($hash)['algoName'], + 'cost' => BCRYPT_COST, +], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), "\n"; -- cgit v1.2.3