<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
divineomega / symfony-password-exposed-bundle example snippets
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use DivineOmega\PasswordExposed\Interfaces\PasswordExposedCheckerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class StandardController extends AbstractController
{
/** @var PasswordExposedCheckerInterface */
protected $checker;
/**
* @param PasswordExposedCheckerInterface $checker
*/
public function __construct(PasswordExposedCheckerInterface $checker)
{
$this->checker = $checker;
}
/**
* @param Request $request
* @return Response
*/
public function simpleAction(Request $request): Response
{
$password = $request->get('password');
if($this->checker->isExposed($password)) {
// do something
// password is exposed
}
return new Response();
}
}
namespace App\Form\Type;
use DivineOmega\PasswordExposed\Symfony\Validator\Constraints\PasswordExposed;
use App\Entity\User;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Form\AbstractType;
/**
* Class RegisterType
*/
class RegisterType extends AbstractType
{
/**
* @inheritdoc
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('username', TextType::class, [
'label' => 'Username',
'constraints' => [
new Assert\NotBlank(),
],
]);
$builder->add('plainPassword', PasswordType::class, [
'label' => 'Password',
'constraints' => [
new Assert\NotBlank(),
new PasswordExposed(),
],
]);
}
/**
* @inheritdoc
*/
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.