Challenge-Response Authentication

This commit is contained in:
xiaomlove
2025-04-05 15:38:40 +07:00
parent bd9b4d7e1d
commit 97dc956c20
28 changed files with 538 additions and 329 deletions

View File

@@ -61,10 +61,15 @@ class NexusWebUserProvider implements UserProvider
*/
public function retrieveByCredentials(array $credentials)
{
if (!empty($credentials['c_secure_uid'])) {
$b_id = base64($credentials["c_secure_uid"],false);
return $this->query->find($b_id);
list($tokenJson, $signature) = explode('.', base64_decode($credentials["c_secure_pass"]));
if (empty($tokenJson) || empty($signature)) {
return null;
}
$tokenData = json_decode($tokenJson, true);
if (!isset($tokenData['user_id'])) {
return null;
}
return $this->retrieveById($tokenData['user_id']);
}
/**
@@ -76,20 +81,9 @@ class NexusWebUserProvider implements UserProvider
*/
public function validateCredentials(Authenticatable $user, array $credentials)
{
if ($credentials["c_secure_login"] == base64("yeah")) {
/**
* Not IP related
* @since 1.8.0
*/
if ($credentials["c_secure_pass"] != md5($user->passhash)) {
return false;
}
} else {
if ($credentials["c_secure_pass"] !== md5($user->passhash)) {
return false;
}
}
return true;
list($tokenJson, $signature) = explode('.', base64_decode($credentials["c_secure_pass"]));
$expectedSignature = hash_hmac('sha256', $tokenJson, $user->auth_key);
return hash_equals($expectedSignature, $signature);
}
public function rehashPasswordIfRequired(Authenticatable $user, #[\SensitiveParameter] array $credentials, bool $force = false)