public function postChangePassword($request, $response) { $validation = $this->validator->validate($request, ['password_old' => v::noWhitespace()->notEmpty()->matchesPassword($this->auth->user()->password), 'password' => v::noWhitespace()->notEmpty()]); if ($validation->failed()) { return $response->withRedirect($this->router->pathFor('auth.password.change')); } $this->auth->user()->setPassword($request->getParam('password')); $this->flash->addMessage('info', 'Your password was changed'); return $response->withRedirect($this->router->pathFor('home')); }
public function postSignUp($request, $response) { $validation = $this->validator->validate($request, ['email' => v::noWhitespace()->notEmpty()->email()->emailAvailable(), 'name' => v::noWhitespace()->notEmpty()->alpha(), 'password' => v::noWhitespace()->notEmpty()]); if ($validation->failed()) { return $response->withRedirect($this->router->pathFor('auth.signup')); } $user = User::create(['email' => $request->getParam('email'), 'name' => $request->getParam('name'), 'password' => password_hash($request->getParam('password'), PASSWORD_DEFAULT)]); $this->flash->addMessage('info', 'You have been signed up'); $this->auth->attempt($user->email, $request->getParam('password')); return $response->withRedirect($this->router->pathFor('home')); }
public static function isValidPassword($password) { return v::noWhitespace()->length(8)->validate($password); }
/** * @brief Validate the server * * @param string $server */ private function validateServer($server) { $validate_server = Validator::noWhitespace()->alnum('.-_')->length(6, 40); return $validate_server->validate($server); }
if (!empty($_POST)) { //If the Post is not empty, it means that it is an insert from the add form $userNameError = null; $passwordError = null; $unidadeError = null; $nameError = null; $emailError = null; //getting POST data $userName = $_POST[username]; $password = $_POST[password]; $unidade = $_POST[unidade]; $name = $_POST[name]; $email = $_POST[email]; //Validation using respect/validation $valid = true; if (!v::noWhitespace()->length(4, 20)->notEmpty()->validate($userName)) { $userNameError = "Por favor digite novamente o nome de usuário, entre 4 e 20 caracteres, sem espaços em branco"; $valid = false; } if (!v::notEmpty()->validate($password)) { $passwordError = "Por favor digite a senha não pode ficar em branco"; $valid = false; } if (!v::notEmpty()->length(1, 5)->validate($unidade)) { $unidadeError = "Por favor digite novamente o unidade, no formato A-00 (letra, traço e número)"; $valid = false; } if (!v::length(3, 80)->notEmpty()->validate($name)) { $nameError = "Por favor digite novamente o nome do morador, entre 3 e 80 caracteres"; $valid = false; }
public function PostChangePassword($request, $response) { // matchesPassword() is a custom validation rule, see Classes/Validation // using $this->container->auth->user() as its parameter is a // preparation for cases when user's password can be reset by an admin // as well (not only the user himselft) $validation = $this->container->validator->validate($request, ['password_old' => v::noWhitespace()->notEmpty()->matchesPassword($this->container, $this->container->auth->user()), 'password' => v::noWhitespace()->notEmpty()]); // on validation failure redirect back to the form. the rest of this // function won't get exectuted if ($validation->failed()) { return $response->withRedirect($this->container->router->pathFor('auth.password.change')); } // change the password, emit flash message and redirect // TODO error handling on failed db->update $user_id = $_SESSION['user'] ?? false; if ($user_id) { $password = $request->getParam('password'); $this->container->db->where('id', $user_id); $this->container->db->update('users', array('password' => password_hash($password, PASSWORD_DEFAULT))); $this->container->flash->addMessage('info', 'Your password was changed'); return $response->withRedirect($this->container->router->pathFor('home')); } }
/** * Verifica se o valor não possui espaços, quebras de linha e tabs * @param string $value * @return boolean */ public function validNowhitespace($value) { if (!v::noWhitespace()->validate($value)) { Factory::log()->warn('Valor não pode possuir espaços e quebras de linha'); return false; } return true; }