Password dictionary WIP

This commit is contained in:
Khushboo Verma
2023-12-05 14:07:17 +01:00
parent d822878fe6
commit 14afed5eb2
3 changed files with 18 additions and 5 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ App::post('/v1/account')
->label('abuse-limit', 10)
->param('userId', '', new CustomId(), 'Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.')
->param('email', '', new Email(), 'User email.')
->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, $project->getAttribute('auths', [])['passwordDictionary'] ?? false), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary'])
->param('password', '', new Text(512, 8), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary10k', 'passwordsDictionary100k', 'passwordsDictionary1M', 'passwordsDictionary10M'])
->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true)
->inject('request')
->inject('response')
+1 -1
View File
@@ -801,7 +801,7 @@ App::patch('/v1/projects/:projectId/auth/password-dictionary')
->label('sdk.response.model', Response::MODEL_PROJECT)
->param('projectId', '', new UID(), 'Project unique ID.')
->param('enabled', false, new Boolean(false), 'Set whether or not to enable checking user\'s password against most commonly used passwords. Default is false.')
->param('length', '10k', new WhiteList(['10k, 100k, 1m, 10m'], true), 'Set the length of the password dictionary to use', true)
->param('length', '10k', new WhiteList(['10k, 100k, 1M, 10M'], true), 'Set the length of the password dictionary to use', true)
->inject('response')
->inject('dbForConsole')
->action(function (string $projectId, bool $enabled, string $length, Response $response, Database $dbForConsole) {
+16 -3
View File
@@ -939,12 +939,20 @@ $register->set('passwordsDictionary100k', function () {
return $content;
});
$register->set('passwordsDictionary1m', function () {
$register->set('passwordsDictionary1M', function () {
$content = \file_get_contents(__DIR__ . '/assets/security/1m-common-passwords');
$content = explode("\n", $content);
$content = array_flip($content);
return $content;
});
$register->set('passwordsDictionary10M', function () {
$content = \file_get_contents(__DIR__ . '/assets/security/1m-common-passwords');
$content = explode("\n", $content);
$content = array_flip($content);
return $content;
});
$register->set('promiseAdapter', function () {
return new Swoole();
});
@@ -1449,9 +1457,14 @@ App::setResource('passwordsDictionary100k', function ($register) {
return $register->get('passwordsDictionary100k');
}, ['register']);
App::setResource('passwordsDictionary1m', function ($register) {
App::setResource('passwordsDictionary1M', function ($register) {
/** @var Utopia\Registry\Registry $register */
return $register->get('passwordsDictionary1m');
return $register->get('passwordsDictionary1M');
}, ['register']);
App::setResource('passwordsDictionary10M', function ($register) {
/** @var Utopia\Registry\Registry $register */
return $register->get('passwordsDictionary10M');
}, ['register']);
App::setResource('servers', function () {