Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for minimum password length upon self registration. #2459

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion webapp/src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Controller;

use App\Controller\Jury\UserController;
use App\Entity\Team;
use App\Entity\TeamAffiliation;
use App\Entity\TeamCategory;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make more sense to store this constant here in the security controller, or possibly in some other global place?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a good suggestion? Since we also use it in the jury controller.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in webapp/config/static.yaml.in? Not sure whether we should also make it configurable from configure or so...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do like that idea, but then maybe we do that in a separate issue / PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had this in the past and had some discussions in #maintainer about it (if I remember correctly).

$this->addFlash('danger', "Password should be " . UserController::MIN_PASSWORD_LENGTH . "+ chars.");
nickygerritsen marked this conversation as resolved.
Show resolved Hide resolved
return $this->redirectToRoute('register');
}

$password = $passwordHasher->hashPassword($user, $plainPass);
$user->setPassword($password);
if ($user->getName() === null) {
$user->setName($user->getUsername());
Expand Down
3 changes: 3 additions & 0 deletions webapp/src/Form/Type/UserRegistrationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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' => [
Expand All @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions webapp/templates/security/register.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
<main>
<div style="text-align: center;">
<img class="mb-4" src="{{ asset('images/DOMjudgelogo.svg') }}" alt="DOMjudge" width="72">
</div>
<div class="container-fluid">
<div class="row">
<div class="col-12">
{% block messages %}
{% include 'partials/messages.html.twig' %}
{% endblock %}
</div>
</div>
</div>
{{ form_start(registration_form, { 'attr': {'class': 'form-signin'} }) }}
<h1 class="h3 mb-3 fw-normal">Register Account</h1>
Expand Down
8 changes: 4 additions & 4 deletions webapp/tests/Unit/Controller/PublicControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 protected]','teamName'=>'Trial','affiliation'=>'none'],'.', $fixtures, $category];
yield[['username'=>'bruteforce', 'teamName'=>'Fib(4)','affiliation'=>'none'],'0112345678', $fixtures, $category];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
yield[['username'=>'bruteforce', 'teamName'=>'Fib(4)','affiliation'=>'none'],'0112345678', $fixtures, $category];
yield[['username'=>'bruteforce', 'teamName'=>'Fib(9)','affiliation'=>'none'],'01123581321', $fixtures, $category];

yield[['username'=>'fullUser', 'name'=>'Full User', 'email'=>'[email protected]','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'=>'[email protected]','teamName'=>'EasyEnough','affiliation'=>'none'],'demo', [...$fixtures, SelfRegisteredUserFixture::class],''];
yield[['username'=>'reusevaluesofexistinguser', 'name'=>'selfregistered user for example team','email'=>'[email protected]','teamName'=>'EasyEnough','affiliation'=>'none'],'demodemodemo', [...$fixtures, SelfRegisteredUserFixture::class],''];
}
}
}
Expand Down
Loading