diff --git a/webapp/src/Controller/SecurityController.php b/webapp/src/Controller/SecurityController.php index e0033e020e..1d3c0d7b2b 100644 --- a/webapp/src/Controller/SecurityController.php +++ b/webapp/src/Controller/SecurityController.php @@ -2,6 +2,7 @@ namespace App\Controller; +use App\Controller\Jury\UserController; use App\Entity\Team; use App\Entity\TeamAffiliation; use App\Entity\TeamCategory; @@ -12,6 +13,7 @@ use Doctrine\ORM\EntityManagerInterface; use Ramsey\Uuid\Uuid; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\HttpException; @@ -103,7 +105,12 @@ public function registerAction( $registration_form->handleRequest($request); if ($registration_form->isSubmitted() && $registration_form->isValid()) { $plainPass = $registration_form->get('plainPassword')->getData(); - $password = $passwordHasher->hashPassword($user, $plainPass); + if (strlen($plainPass) < UserController::MIN_PASSWORD_LENGTH) { + $this->addFlash('danger', "Password should be " . UserController::MIN_PASSWORD_LENGTH . "+ chars."); + return $this->redirectToRoute('register'); + } + + $password = $passwordHasher->hashPassword($user, $plainPass); $user->setPassword($password); if ($user->getName() === null) { $user->setName($user->getUsername()); diff --git a/webapp/src/Form/Type/UserRegistrationType.php b/webapp/src/Form/Type/UserRegistrationType.php index 84edde72f7..5a7a271b72 100644 --- a/webapp/src/Form/Type/UserRegistrationType.php +++ b/webapp/src/Form/Type/UserRegistrationType.php @@ -2,6 +2,7 @@ namespace App\Form\Type; +use App\Controller\Jury\UserController; use App\Entity\Role; use App\Entity\Team; use App\Entity\TeamAffiliation; @@ -171,6 +172,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'placeholder' => 'Password', 'autocomplete' => 'new-password', 'spellcheck' => 'false', + 'minlength' => UserController::MIN_PASSWORD_LENGTH, ], ], 'second_options' => [ @@ -179,6 +181,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'placeholder' => 'Repeat Password', 'autocomplete' => 'new-password', 'spellcheck' => 'false', + 'minlength' => UserController::MIN_PASSWORD_LENGTH, ], ], 'mapped' => false, diff --git a/webapp/templates/security/register.html.twig b/webapp/templates/security/register.html.twig index 90075a9ec1..47134dc690 100644 --- a/webapp/templates/security/register.html.twig +++ b/webapp/templates/security/register.html.twig @@ -13,6 +13,15 @@
DOMjudge +
+
+
+
+ {% block messages %} + {% include 'partials/messages.html.twig' %} + {% endblock %} +
+
{{ form_start(registration_form, { 'attr': {'class': 'form-signin'} }) }}

Register Account

diff --git a/webapp/tests/Unit/Controller/PublicControllerTest.php b/webapp/tests/Unit/Controller/PublicControllerTest.php index c76e7e6859..6baecaa113 100644 --- a/webapp/tests/Unit/Controller/PublicControllerTest.php +++ b/webapp/tests/Unit/Controller/PublicControllerTest.php @@ -210,17 +210,17 @@ public function selfRegisterProvider(): Generator continue; } yield[['username'=>'minimaluser', 'teamName'=>'NewTeam','affiliation'=>'none'],'shirt-recognize-bar-together', $fixtures, $category]; - yield[['username'=>'bruteforce', 'teamName'=>'Fib(4)','affiliation'=>'none'],'0112', $fixtures, $category]; - yield[['username'=>'fullUser', 'name'=>'Full User', 'email'=>'email@domain.com','teamName'=>'Trial','affiliation'=>'none'],'.', $fixtures, $category]; + yield[['username'=>'bruteforce', 'teamName'=>'Fib(4)','affiliation'=>'none'],'0112345678', $fixtures, $category]; + yield[['username'=>'fullUser', 'name'=>'Full User', 'email'=>'email@domain.com','teamName'=>'Trial','affiliation'=>'none'],'..........', $fixtures, $category]; yield[['username'=>'student@', 'teamName'=>'Student@Uni', 'affiliation'=>'new','affiliationName'=>'NewUni','affiliationShortName'=>'nu'],'p@ssword_Is_long', $fixtures, $category]; yield[['username'=>'winner@', 'teamName'=>'FunnyTeamname', 'affiliation'=>'new','affiliationName'=>'SomeUni','affiliationShortName'=>'su','affiliationCountry'=>'SUR'],'p@ssword_Is_long', $fixtures, $category]; yield[['username'=>'klasse', 'teamName'=>'Klasse', 'affiliation'=>'existing','existingAffiliation'=>'1'],'p@ssword_Is_long', $fixtures, $category]; yield[['username'=>'newinstsamecountry', 'name'=>'CompetingDutchTeam', 'teamName'=>'SupperT3@m','affiliation'=>'new','affiliationName'=>'Vrije Universiteit', - 'affiliationShortName'=>'vu','affiliationCountry'=>'NLD'],'demo', $fixtures, $category]; + 'affiliationShortName'=>'vu','affiliationCountry'=>'NLD'],'demodemodemo', $fixtures, $category]; if (count($fixtures)===1) { - yield[['username'=>'reusevaluesofexistinguser', 'name'=>'selfregistered user for example team','email'=>'electronic@mail.tld','teamName'=>'EasyEnough','affiliation'=>'none'],'demo', [...$fixtures, SelfRegisteredUserFixture::class],'']; + yield[['username'=>'reusevaluesofexistinguser', 'name'=>'selfregistered user for example team','email'=>'electronic@mail.tld','teamName'=>'EasyEnough','affiliation'=>'none'],'demodemodemo', [...$fixtures, SelfRegisteredUserFixture::class],'']; } } }