<?php

namespace ThurData\Servers\KerioEmail\App\Validators;


use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\Validators\BaseValidator;
use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\Validators\boolen;

/**
 *
 * Created by PhpStorm.
 * User: ThurData
 * Date: 10.10.19
 * Time: 11:20
 * Class PasswordsValidator
 */
class PasswordsValidator extends BaseValidator
{


    /**
     * return true if data is valid, false if not,
     * add error messages to $errorsList
     *
     * @param $data mixed
     * @param $additionalData mixed
     * @return boolen
     */
    protected function validate($data, $additionalData = null)
    {
        if(strlen($data) < 8)
        {
            $this->addValidationError('passwordCharsLengthError');
            return false;
        }

        if (!preg_match('#[0-9]+#', $data)) {
            $this->addValidationError('passwordNumberError');
            return false;
        }
    
        if (!preg_match('#[A-Z]+#', $data)) {
            $this->addValidationError('passwordUpperError');
            return false;
        }     
    
        if (!preg_match('#[a-z]+#', $data)) {
            $this->addValidationError('passwordLowerError');
            return false;
        }     
    
        if (!preg_match('#[^\w]+#', $data)) {
            $this->addValidationError('passwordSpecialError');
            return false;
        }
        return true;
    }
}