controle cohérance pwd

This commit is contained in:
afornerot 2021-01-21 15:22:59 +01:00
parent 7c26cdb57f
commit b8ee13c49b
3 changed files with 26 additions and 5 deletions

View File

@ -6,8 +6,8 @@ use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Cadoles\CoreBundle\Validator as CadolesCoreAssert;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
use Cadoles\CoreBundle\Validator\Password;
/** /**
* @ORM\Entity * @ORM\Entity
@ -51,6 +51,11 @@ class Registration implements UserInterface, \Serializable
* @ORM\Column(type="string", length=250) * @ORM\Column(type="string", length=250)
*/ */
private $password; private $password;
/**
* @CadolesCoreAssert\Password()
*/
private $passwordplain;
/** /**
* @ORM\Column(type="string", length=250) * @ORM\Column(type="string", length=250)
@ -184,7 +189,10 @@ class Registration implements UserInterface, \Serializable
public function setPassword($password) public function setPassword($password)
{ {
if($password!=$this->password&&$password!=""){ if($password!=$this->password&&$password!=""){
// Placer le password non encodé dans une variable tempo sur laquel on va appliquer la contraite
$this->passwordplain = $password;
// Password encrypté format openldap // Password encrypté format openldap
mt_srand((double)microtime()*1000000); mt_srand((double)microtime()*1000000);
$this->salt = pack("CCCC", mt_rand(), mt_rand(), mt_rand(), mt_rand()); $this->salt = pack("CCCC", mt_rand(), mt_rand(), mt_rand(), mt_rand());

View File

@ -10,6 +10,8 @@ use Cadoles\CoreBundle\Validator as CadolesCoreAssert;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
/** /**
* @ORM\Entity * @ORM\Entity
* @ORM\Table(name="user") * @ORM\Table(name="user")
@ -29,6 +31,12 @@ class User implements UserInterface, \Serializable
/** /**
* @ORM\Column(type="string", length=50, unique=true) * @ORM\Column(type="string", length=50, unique=true)
* @Assert\Length(
* min = "5",
* max = "25",
* minMessage = "Votre nom doit faire au moins {{ limit }} caractères",
* maxMessage = "Votre nom ne peut pas être plus long que {{ limit }} caractères"
* )
*/ */
private $username; private $username;
@ -44,9 +52,13 @@ class User implements UserInterface, \Serializable
/** /**
* @ORM\Column(type="string", length=250) * @ORM\Column(type="string", length=250)
* @CadolesCoreAssert\PasswordValidator
*/ */
private $password; private $password;
/**
* @CadolesCoreAssert\Password()
*/
private $passwordplain;
/** /**
* @ORM\Column(type="string", length=250) * @ORM\Column(type="string", length=250)
@ -393,6 +405,9 @@ class User implements UserInterface, \Serializable
public function setPassword($password) public function setPassword($password)
{ {
if($password!=$this->password&&$password!=""){ if($password!=$this->password&&$password!=""){
// Placer le password non encodé dans une variable tempo sur laquel on va appliquer la contraite
$this->passwordplain = $password;
// Password encrypté format openldap // Password encrypté format openldap
mt_srand((double)microtime()*1000000); mt_srand((double)microtime()*1000000);
$this->salt = pack("CCCC", mt_rand(), mt_rand(), mt_rand(), mt_rand()); $this->salt = pack("CCCC", mt_rand(), mt_rand(), mt_rand(), mt_rand());

View File

@ -11,8 +11,6 @@ class PasswordValidator extends ConstraintValidator
{ {
public function validate($value, Constraint $constraint) public function validate($value, Constraint $constraint)
{ {
$this->context->addViolation($constraint->message);
if(!empty($value)) { if(!empty($value)) {
if (strlen($value) < '8') { if (strlen($value) < '8') {
$this->context->addViolation($constraint->message); $this->context->addViolation($constraint->message);