Skip to content

Commit

Permalink
Fix auth uncatched exception
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-schindler committed Oct 27, 2022
1 parent b2e61c9 commit f310665
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Backend/Core/Data/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
/**
* This class allow a more direct access to all Database
* classes for easier access to things like transactions
*
* To close the connection, the instance has to be set to `null`
*
* @since 2.0.0
*/
class Database extends PDO
Expand Down
18 changes: 11 additions & 7 deletions Backend/Core/Functions/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ public static function validateToken(?string $token = null): bool {
if (($decoded = base64_decode($token)) !== false) {
$decToken = explode(".", $decoded);
if (count($decToken) === 3) {
if (($uuid = base64_decode($decToken[0])) != false && ($passHash = base64_decode($decToken[1])) != false && ($validUntil = base64_decode($decToken[2])) != false) {
$dayDiff = (new DateTime())->diff(new DateTime($validUntil))->format('%r%a');
if (($uuid = base64_decode($decToken[0])) && ($passHash = base64_decode($decToken[1])) && ($validUntil = base64_decode($decToken[2]))) {
try {
$dayDiff = (new DateTime())->diff(new DateTime($validUntil))->format('%r%a');

// Date is between 1 and 30 days in the future
if ($dayDiff > 0 && $dayDiff <= 30) {
$q = new Query("SELECT `password` FROM `User` WHERE `uuid`=:uuid;", [":uuid" => $uuid]);
if ($q->count() === 1 && ($user = $q->fetch()) !== null) {
return password_verify($user['password'], $passHash);
// Date is between 1 and 30 days in the future
if ($dayDiff > 0 && $dayDiff <= 30) {
$q = new Query("SELECT `password` FROM `User` WHERE `uuid`=:uuid;", [":uuid" => $uuid]);
if ($q->count() === 1 && ($user = $q->fetch()) !== null) {
return password_verify($user['password'], $passHash);
}
}
} catch (Exception) {
return false;
}
}
}
Expand Down

0 comments on commit f310665

Please sign in to comment.