Update RegisterValidator.php

This commit is contained in:
Ivor Barhansky 2024-04-24 15:08:49 +00:00
parent 48f6cbeef0
commit 30e5f89118
1 changed files with 16 additions and 22 deletions

View File

@ -12,7 +12,13 @@ class RegisterValidator
{ {
$login = preg_replace('!\s+!', ' ', $login); // remove inner spaces $login = preg_replace('!\s+!', ' ', $login); // remove inner spaces
$login = trim($login); // remove outer spaces $login = trim($login); // remove outer spaces
if ($this->loginIsAllowed($login) && !$this->loginIsMixed($login)) { if (
$this->loginIsAllowed($login) &&
!$this->loginIsMixed($login) &&
mb_strlen($login < 2) &&
mb_strlen($login) > 16 &&
!strpos("!@#$%^&*()\+|/'\"", $login)
) {
$this->login = $login; $this->login = $login;
} }
return $this; return $this;
@ -47,7 +53,7 @@ class RegisterValidator
public function setPassword($password, $passwordVerify) public function setPassword($password, $passwordVerify)
{ {
if ($this->password === $passwordVerify) { if ($this->password === $passwordVerify && mb_strlen($password) > 3) {
$this->password = md5($password); $this->password = md5($password);
} }
return $this; return $this;
@ -70,26 +76,14 @@ class RegisterValidator
return $this; return $this;
} }
public function verify() public function get()
{ {
if (!empty($this->login) && !empty($this->email) && !empty($this->password) && !empty($this->birthday)) { return [
return [ 'login' => $this->login,
'login' => $this->login, 'email' => $this->email,
'email' => $this->email, 'password' => $this->password,
'password' => $this->password, 'birthday' => $this->birthday,
'birthday' => $this->birthday, 'sex' => $this->sex,
'sex' => $this->sex, ];
];
}
return [];
} }
} }
$rv = new RegisterValidator();
$values = $rv
->setLogin($login)
->setPassword($pass1, $pass2)
->setEmail($email)
->setBirthday($birthday)
->setSex($sex)
->verify();