Alters validator object and applies password constraints.

@param \Cake\Validation\Validator $validator Validator object
@return \Cake\Validation\Validator
550918
protected function _applyPasswordPolicies(Validator $validator)
    {
        $rules = [];
        if (plugin('User')->settings('password_min_length')) {
            $len = intval(plugin('User')->settings('password_min_length'));
            $rules['length'] = [
                'rule' => function ($value, $context) use ($len) {
                    return mb_strlen($this->_getRawPassword($context)) >= $len;
                },
                'message' => __d('user', 'Password must be at least {0} characters long.', $len),
            ];
        }

        if (plugin('User')->settings('password_uppercase')) {
            $rules['uppercase'] = [
                'rule' => function ($value, $context) {
                    return (bool)preg_match('/[\p{Lu}]/u', $this->_getRawPassword($context));
                },
                'message' => __d('user', 'Password must contain at least one uppercase character (A-Z).'),
            ];
        }

        if (plugin('User')->settings('password_lowercase')) {
            $rules['lowercase'] = [
                'rule' => function ($value, $context) {
                    return (bool)preg_match('/[\p{Ll}]/u', $this->_getRawPassword($context));
                },
                'message' => __d('user', 'Password must contain at least one lowercase character (a-z).'),
            ];
        }

        if (plugin('User')->settings('password_number')) {
            $rules['number'] = [
                'rule' => function ($value, $context) {
                    return (bool)preg_match('/[\p{N}]/u', $this->_getRawPassword($context));
                },
                'message' => __d('user', 'Password must contain at least one numeric character (1-9).'),
            ];
        }

        if (plugin('User')->settings('password_non_alphanumeric')) {
            $rules['non_alphanumeric'] = [
                'rule' => function ($value, $context) {
                    return (bool)preg_match('/[^\p{L}\p{N}]/u', $this->_getRawPassword($context));
                },
                'message' => __d('user', 'Password must contain at least one non-alphanumeric character (e.g. #%?).'),
            ];
        }

        $validator->add('password', $rules);

        return $validator;
    }
548953
public function validationDefault(Validator $validator)
    {
        $validator
            ->uuid('id')
            ->allowEmpty('id', 'create');

        $validator
            ->requirePresence('name', 'create')
            ->notEmpty('name');

        $validator
            ->allowEmpty('color');

        $validator
            ->allowEmpty('icon');

        $validator
            ->allowEmpty('source');

        return $validator;
    }
1275408
public function validationDefault(Validator $validator)
    {
        $validator
            ->uuid('id')
            ->allowEmpty('id', 'create');

        $validator
            ->allowEmpty('source');

        $validator
            ->requirePresence('title', 'create')
            ->allowEmpty('title');

        $validator
            ->requirePresence('content', 'create')
            ->allowEmpty('content');

        $validator
            ->dateTime('start_date')
            ->allowEmpty('start_date');

        $validator
            ->dateTime('end_date')
            ->allowEmpty('end_date');

        $validator
            ->time('duration')
            ->allowEmpty('duration');

        return $validator;
    }
693987
public function validationDefault(Validator $validator)
    {
        $validator
            ->add('id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('id', 'create');

        $validator
            ->requirePresence('upload_id', 'create')
            ->notEmpty('upload_id');

        $validator
            ->requirePresence('original_filename', 'create')
            ->notEmpty('original_filename');

        $validator
            ->requirePresence('unique_filename', 'create')
            ->notEmpty('unique_filename');

        $validator
            ->allowEmpty('subfolder');

        $validator
            ->allowEmpty('mimetype');

        $validator
            ->add('size', 'valid', ['rule' => 'numeric'])
            ->requirePresence('size', 'create')
            ->notEmpty('size');

        $validator
            ->requirePresence('hash', 'create')
            ->notEmpty('hash');

        $validator
            ->add('upload_complete', 'valid', ['rule' => 'boolean'])
            ->requirePresence('upload_complete', 'create')
            ->notEmpty('upload_complete');

        $validator
            ->allowEmpty('label');

        $validator
            ->add('created_by', 'valid', ['rule' => 'numeric'])
            ->requirePresence('created_by', 'create')
            ->notEmpty('created_by');

        $validator
            ->add('modified_by', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('modified_by');

        return $validator;
    }
818755
public function validationDefault(Validator $validator) {
        $validator
                ->allowEmpty('id', 'create')
                ->requirePresence('parent', 'create')
                ->notEmpty('parent')
                ->requirePresence('name', 'create')
                ->notEmpty('name')
                ->add('name', 'unique', ['rule' => 'validateUnique', 'provider' => 'table'])
                ->requirePresence('content_title', 'create')
                ->notEmpty('content_title')
                ->requirePresence('content_description', 'create')
                ->notEmpty('content_description')
                ->requirePresence('content_excerpt', 'create')
                ->notEmpty('content_excerpt')
                ->add('content_deadline', 'valid', ['rule' => 'datetime'])
                ->requirePresence('content_deadline', 'create')
                ->notEmpty('content_deadline')
                ->requirePresence('content_password', 'create')
                ->notEmpty('content_password')
                ->requirePresence('content_status', 'create')
                ->notEmpty('content_status')
                ->requirePresence('content_path', 'create')
                ->notEmpty('content_path')
                ->requirePresence('content_type', 'create')
                ->notEmpty('content_type')
                ->requirePresence('content_mime_type', 'create')
                ->notEmpty('content_mime_type')
                ->add('publish_start', 'valid', ['rule' => 'datetime'])
                ->requirePresence('publish_start', 'create')
                ->notEmpty('publish_start')
                ->add('publish_end', 'valid', ['rule' => 'datetime'])
                ->requirePresence('publish_end', 'create')
                ->notEmpty('publish_end')
                ->add('author', 'valid', ['rule' => 'numeric'])
                ->requirePresence('author', 'create')
                ->notEmpty('author')
                ->add('menu_order', 'valid', ['rule' => 'numeric'])
                ->requirePresence('menu_order', 'create')
                ->notEmpty('menu_order');

        return $validator;
    }
739770
protected function removeValidator(Validator $validator) : Component
    {
        $hash = spl_object_hash($validator);
        unset($this->validators[$hash]);

        return $this;
    }
441538
public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmpty('id', 'create');

        $validator
            ->allowEmpty('name');

        $validator
            ->allowEmpty('bio');

        $validator
            ->allowEmpty('url');

        $validator
            ->allowEmpty('company');

        $validator
            ->allowEmpty('location');

        return $validator;
    }
739108
public function addValidator(Validator $validator) : Component
    {
        $hash = spl_object_hash($validator);
        $this->validators[$hash] = $validator;

        return $this;
    }
322219
public function validate(Validator $validator = null)
    {
        if (null === $validator) {
            $validator = new Validator(new ClassMetadataFactory(new StaticMethodLoader()), new ConstraintValidatorFactory(), new DefaultTranslator());
        }

        $failureMap = new ConstraintViolationList();

        if (!$this->alreadyInValidation) {
            $this->alreadyInValidation = true;
            $retval = null;


            $retval = $validator->validate($this);
            if (count($retval) > 0) {
                $failureMap->addAll($retval);
            }

            if (null !== $this->collAttributeAttributeTypes) {
                foreach ($this->collAttributeAttributeTypes as $referrerFK) {
                    if (method_exists($referrerFK, 'validate')) {
                        if (!$referrerFK->validate($validator)) {
                            $failureMap->addAll($referrerFK->getValidationFailures());
                        }
                    }
                }
            }
            if (null !== $this->collAttributeTypeI18ns) {
                foreach ($this->collAttributeTypeI18ns as $referrerFK) {
                    if (method_exists($referrerFK, 'validate')) {
                        if (!$referrerFK->validate($validator)) {
                            $failureMap->addAll($referrerFK->getValidationFailures());
                        }
                    }
                }
            }

            $this->alreadyInValidation = false;
        }

        $this->validationFailures = $failureMap;

        return (Boolean) (!(count($this->validationFailures) > 0));

    }
953309
public function validationDefault(Validator $validator)
    {
        $validator
            ->requirePresence('name')
            ->notEmpty('name', __d('user', 'You must provide a name.'))
            ->requirePresence('username', 'create')
            ->add('username', [
                'characters' => [
                    'rule' => function ($value, $context) {
                        return preg_match('/^[a-zA-Z0-9\_]{3,}$/', $value) === 1;
                    },
                    'provider' => 'table',
                    'message' => __d('user', 'Invalid username. Only letters, numbers and "_" symbol, and at least three characters long.'),
                ],
            ])
            ->requirePresence('email')
            ->notEmpty('email', __d('user', 'e-mail cannot be empty.'))
            ->requirePresence('password', 'create')
            ->allowEmpty('password', 'update')
            ->add('password', [
                'compare' => [
                    'rule' => function ($value, $context) {
                        $value2 = isset($context['data']['password2']) ? $context['data']['password2'] : false;

                        return (new DefaultPasswordHasher)->check($value2, $value) || $value == $value2;
                    },
                    'message' => __d('user', 'Password mismatch.'),
                ]
            ])
            ->allowEmpty('web')
            ->add('web', 'validUrl', [
                'rule' => 'url',
                'message' => __d('user', 'Invalid URL.'),
            ]);

        return $this->_applyPasswordPolicies($validator);
    }
1293348
public function withValidator($validator): void
    {
        $validator->after(function ($validator) {
            if (! auth()->guard($this->route('guard'))->getProvider()->validateCredentials($this->user($this->route('guard')), ['password' => $this->get('old_password')])) {
                $validator->errors()->add('old_password', trans('cortex/auth::messages.account.wrong_password'));
            }

            if (auth()->guard($this->route('guard'))->getProvider()->validateCredentials($this->user($this->route('guard')), ['password' => $this->get('new_password')])) {
                $validator->errors()->add('new_password', trans('cortex/auth::messages.account.different_password'));
            }
        });
    }
56101
public function withValidator($validator)
    {
        if ($validator->passes()) {
            $validator->after(function ($validator) {

                try {
                    // get validated data
                    $data = $this->validated();

                    // Set temporary DB connection
                    config(['database.connections.mysql' => [
                        'driver' => 'mysql',
                        'host' =>  $data['DB_HOST'],
                        'database' => $data['DB_DATABASE'],
                        'prefix' => $data['DB_PREFIX'],
                        'username' => $data['DB_USERNAME'],
                        'password' => $data['DB_PASSWORD'],
                        'charset' => 'utf8',
                        'collation' => 'utf8_unicode_ci',
                        'strict' => true,
                        'engine' => 'InnoDB',
                    ]]);

                    // Check DB connection and exists table
                    \DB::purge('mysql');
                    \DB::reconnect('mysql');
                    \DB::setTablePrefix($data['DB_PREFIX']);
                    \DB::connection()->getPdo();
                    if (is_null(\DB::connection('mysql')->getDatabaseName())) {
                        throw new InstallerFailed(__('msg.not_dbconnect'));
                    }

                    // 3 Manipulation of the database
                    \DB::beginTransaction();

                    // Make migrate
                    $exitCode = \Artisan::call('migrate', ['--force' => true]);
                    $outputMigrate = \Artisan::output();
                    session()->flash('flash_output_migrate', $outputMigrate);

                    \DB::commit();
                } catch (\InstallerFailed $e) {
                    $validator->errors()->add('database', $e->getMessage());
                } catch (\PDOException $e) {
                    $validator->errors()->add('database', $e->getMessage());
                } finally {
                    \DB::rollback();
                }

            });
        }

        return $validator;
    }
1158687
public function setValidator(Validator $validator)
    {
        $this->validator = $validator;
        
        $validator->configureRule($this);
        
        return $this;
    }
1043625
public function validationDefault(Validator $validator)
    {
        $validator
            ->add('id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('id', 'create');

        $validator
            ->add('email', 'valid', ['rule' => 'email'])
            ->requirePresence('email', 'create')
            ->notEmpty('email');

        $validator
            ->requirePresence('password', 'create')
            ->notEmpty('password');

        return $validator;
    }
73286
protected function registerValidationRules($validator)
    {
        /**
         * elfinder validator
         */
        $validator->resolver(function($translator, $data, $rules, $messages)
        {
            return new BaseValidator($translator, $data, $rules, $messages);
        });
        $validator->replacer('elfinder_max', function($message, $attribute, $rule, $parameters) {
            return str_replace(':size',$parameters[0],$message);
        });
        $validator->replacer('elfinder', function($message, $attribute, $rule, $parameters) {
            return str_replace(':values',implode(', ', $parameters),$message);
        });

    }
1202754
public function validate(Validator $validator)
    {
        $handler = $this->get('metadata')->get('handler');
        if (class_exists($handler)) {
            $handler = new $handler();

            return $handler->validate($this, $validator);
        }
    }
697970
protected function _buildValidator(Validator $validator)
    {
        $validator->provider('googleRecaptcha', 'Wasabi\Core\Model\Validation\GoogleRecaptchaValidationProvider');

        return $validator
            ->notEmpty('name', __d('wasabi_core', 'Please enter your name.'))
            ->notEmpty('email', __d('wasabi_core', 'Please enter your email address.'))
            ->add('email', 'email', ['rule' => 'email', 'message' => __d('wasabi_core', 'Please enter a valid email address.')])
            ->notEmpty('subject', __d('wasabi_core', 'Please enter a subject for your contact request.'))
            ->notEmpty('message', __d('wasabi_core', 'Please provide a message for your contact request.'))
            ->notEmpty('g-recaptcha-response', __d('wasabi_core', 'Please confirm you are human.'))
            ->add('g-recaptcha-response', 'googleRecaptcha', [
                'rule' => 'googleRecaptcha',
                'message' => __d('wasabi_core', 'Please confirm you are human.'),
                'provider' => 'googleRecaptcha'
            ]);
    }