Skip to content
Merged
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
22 changes: 22 additions & 0 deletions src/Controller/User/Ajax/PasswordStrengthController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Controller\User\Ajax;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use SumoCoders\FrameworkCoreBundle\Security\PasswordStrengthService;

class PasswordStrengthController extends AbstractController
{
public function __invoke(
Request $request,
PasswordStrengthService $passwordStrengthService
): Response {
$password = json_decode($request->getContent(), true)['password'] ?? '';

return $this->json([
'strength' => $passwordStrengthService->estimateStrength($password),
]);
}
}
2 changes: 2 additions & 0 deletions src/DataTransferObject/User/UserDataTransferObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

use App\Validator\User\UniqueEmail;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NoSuspiciousCharacters;
use Symfony\Component\Validator\Constraints\NotBlank;

class UserDataTransferObject
{
#[Email]
#[NotBlank]
#[UniqueEmail]
#[NoSuspiciousCharacters]
public string $email;

/**
Expand Down
6 changes: 6 additions & 0 deletions src/Message/User/RegisterUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
namespace App\Message\User;

use App\DataTransferObject\User\UserDataTransferObject;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Constraints\NotBlank;

class RegisterUser extends UserDataTransferObject
{
#[NotBlank]
#[Assert\PasswordStrength([
'minScore' => Assert\PasswordStrength::STRENGTH_STRONG,
])]
#[Assert\NotCompromisedPassword()]
#[Assert\Length(min: 12)]
public string $password;
}
6 changes: 6 additions & 0 deletions src/Message/User/ResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
namespace App\Message\User;

use App\Entity\User\User;
use Symfony\Component\Validator\Constraints as Assert;

class ResetPassword
{
#[Assert\PasswordStrength([
'minScore' => Assert\PasswordStrength::STRENGTH_STRONG,
])]
#[Assert\NotCompromisedPassword()]
#[Assert\Length(min: 12)]
public string $password;

public function __construct(private readonly User $user)
Expand Down
10 changes: 10 additions & 0 deletions templates/user/password-strength-meter.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="password-strength-meter">
<div class="meter-section rounded me-2"></div>
<div class="meter-section rounded me-2"></div>
<div class="meter-section rounded me-2"></div>
<div class="meter-section rounded me-2"></div>
<div class="meter-section rounded"></div>
</div>
<div class="mb-3">
<small>{{ 'Use 12 or more characters with a mix of letters, numbers & symbols'|trans }}</small>
</div>
6 changes: 5 additions & 1 deletion templates/user/profile.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
<h1>{{ 'Change your password'|trans }}</h1>
{{ form_start(form) }}
{{ form_errors(form) }}
{{ form_row(form.password) }}
<div data-role="check-password" data-route="{{ path('admin_user_ajax_password_strength') }}">
{{ form_row(form.password.first) }}
{% include '/user/password-strength-meter.html.twig' %}
</div>
{{ form_row(form.password.second) }}

<input type="submit" class="btn btn-secondary" value="{{ 'Confirm'|trans }}" />
{{ form_end(form) }}
Expand Down
6 changes: 5 additions & 1 deletion templates/user/reset.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
{% block main %}
{{ form_start(form) }}
{{ form_errors(form) }}
{{ form_row(form.password) }}
<div data-role="check-password" data-route="{{ path('admin_user_ajax_password_strength') }}">
{{ form_row(form.password.first) }}
{% include '/user/password-strength-meter.html.twig' %}
</div>
{{ form_row(form.password.second) }}

<input type="submit" class="btn btn-secondary" value="{{ 'Confirm'|trans }}" />
{{ form_end(form) }}
Expand Down
19 changes: 0 additions & 19 deletions translations/security.nl.yaml

This file was deleted.

134 changes: 0 additions & 134 deletions translations/validators.nl.yaml

This file was deleted.