Skip to content

Instantly share code, notes, and snippets.

@Kcko
Last active June 26, 2025 17:04
Show Gist options
  • Save Kcko/1720f32ea5f94387b7c2d20ed504d8fb to your computer and use it in GitHub Desktop.
Save Kcko/1720f32ea5f94387b7c2d20ed504d8fb to your computer and use it in GitHub Desktop.
<?php
// Pro hesla uživatelů
$hashedPassword = password_hash($userPassword, PASSWORD_DEFAULT);
if (password_verify($inputPassword, $hashedPassword)) {
// přihlášen
}
// Pro bearer tokeny
$token = hash_hmac('sha256', $windowStart, 'secret');
if (hash_equals($token, $receivedToken)) {
// autorizován
}
<?php
$currentTime = time();
$timeWindow = 500; // token expiration
$expectedToken = hash_hmac('sha256', $currentTime - ($currentTime % $timeWindow), 'OUR_ANY_SECRET');
// echo hash_equals($expectedToken, $anyTokenFromGetorPost);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment