diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 7a2d268d78..c55940591d 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -99,7 +99,8 @@ App::post('/v1/account') } } - if (str_contains($passwordsDB, $password)) { + $passwordDictionary = $project->getAttribute('auths', []['passwordDictionary']) ?? false; + if ($passwordDictionary && str_contains($passwordsDB, $password)) { throw new Exception( Exception::USER_PASSWORD_IN_DICTIONARY, 'The password is among the common passwords in dictionary.', @@ -108,7 +109,6 @@ App::post('/v1/account') } $passwordHistory = $project->getAttribute('auths', [])['passwordHistory'] ?? 0; - $password = Auth::passwordHash($password, Auth::DEFAULT_ALGO, Auth::DEFAULT_ALGO_OPTIONS); try { $userId = $userId == 'unique()' ? ID::unique() : $userId; @@ -1535,7 +1535,11 @@ App::patch('/v1/account/password') throw new Exception(Exception::USER_INVALID_CREDENTIALS); } - if (str_contains($passwordsDB, $password)) { + + $newPassword = Auth::passwordHash($password, Auth::DEFAULT_ALGO, Auth::DEFAULT_ALGO_OPTIONS); + + $passwordDictionary = $project->getAttribute('auths', []['passwordDictionary']) ?? false; + if ($passwordDictionary && str_contains($passwordsDB, $password)) { throw new Exception( Exception::USER_PASSWORD_IN_DICTIONARY, 'The password is among the common passwords in dictionary.', @@ -1543,8 +1547,6 @@ App::patch('/v1/account/password') ); } - $newPassword = Auth::passwordHash($password, Auth::DEFAULT_ALGO, Auth::DEFAULT_ALGO_OPTIONS); - $historyLimit = $project->getAttribute('auths', [])['passwordHistory'] ?? 0; $history = []; if ($historyLimit > 0) { diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index b087237422..de6b192296 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -114,7 +114,8 @@ App::post('/v1/users') ->inject('events') ->action(function (string $userId, ?string $email, ?string $phone, ?string $password, string $name, string $passwordsDB, Response $response, Document $project, Database $dbForProject, Event $events) { - if (str_contains($passwordsDB, $password)) { + $passwordDictionary = $project->getAttribute('auths', []['passwordDictionary']) ?? false; + if ($passwordDictionary && str_contains($passwordsDB, $password)) { throw new Exception( Exception::USER_PASSWORD_IN_DICTIONARY, 'The password is among the common passwords in dictionary.', @@ -815,7 +816,10 @@ App::patch('/v1/users/:userId/password') throw new Exception(Exception::USER_NOT_FOUND); } - if (str_contains($passwordsDB, $password)) { + $newPassword = Auth::passwordHash($password, Auth::DEFAULT_ALGO, Auth::DEFAULT_ALGO_OPTIONS); + + $passwordDictionary = $project->getAttribute('auths', []['passwordDictionary']) ?? false; + if ($passwordDictionary && str_contains($passwordsDB, $password)) { throw new Exception( Exception::USER_PASSWORD_IN_DICTIONARY, 'The password is among the common passwords in dictionary.', @@ -823,8 +827,6 @@ App::patch('/v1/users/:userId/password') ); } - $newPassword = Auth::passwordHash($password, Auth::DEFAULT_ALGO, Auth::DEFAULT_ALGO_OPTIONS); - $historyLimit = $project->getAttribute('auths', [])['passwordHistory'] ?? 0; $history = []; if ($historyLimit > 0) {