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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Cadoles\CoreBundle\Validator as CadolesCoreAssert;
use Symfony\Component\Validator\Constraints as Assert;
use Cadoles\CoreBundle\Validator\Password;
/**
* @ORM\Entity
@ -51,6 +51,11 @@ class Registration implements UserInterface, \Serializable
* @ORM\Column(type="string", length=250)
*/
private $password;
/**
* @CadolesCoreAssert\Password()
*/
private $passwordplain;
/**
* @ORM\Column(type="string", length=250)
@ -184,7 +189,10 @@ class Registration implements UserInterface, \Serializable
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
mt_srand((double)microtime()*1000000);
$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;
/**
* @ORM\Entity
* @ORM\Table(name="user")
@ -29,6 +31,12 @@ class User implements UserInterface, \Serializable
/**
* @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;
@ -44,9 +52,13 @@ class User implements UserInterface, \Serializable
/**
* @ORM\Column(type="string", length=250)
* @CadolesCoreAssert\PasswordValidator
*/
private $password;
/**
* @CadolesCoreAssert\Password()
*/
private $passwordplain;
/**
* @ORM\Column(type="string", length=250)
@ -393,6 +405,9 @@ class User implements UserInterface, \Serializable
public function setPassword($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
mt_srand((double)microtime()*1000000);
$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)
{
$this->context->addViolation($constraint->message);
if(!empty($value)) {
if (strlen($value) < '8') {
$this->context->addViolation($constraint->message);