Find dates without separators in a password.

@param string $password

@return array
482661
protected static function datesWithoutSeparators($password)
    {
        $dateMatches = [];

        // 1197 is length-4, 01011997 is length 8
        foreach (static::findAll($password, '/(\d{4,8})/') as $captures) {
            $capture = $captures[1];
            $begin = $capture['begin'];
            $end = $capture['end'];

            $token = $capture['token'];
            $tokenLen = strlen($token);

            // Create year candidates.
            $candidates1 = [];
            if ($tokenLen <= 6) {
                // 2 digit year prefix (990112)
                $candidates1[] = [
                    'daymonth' => substr($token, 2),
                    'year' => substr($token, 0, 2),
                    'begin' => $begin,
                    'end' => $end,
                ];
                // 2 digit year suffix (011299)
                $candidates1[] = [
                    'daymonth' => substr($token, 0, $tokenLen - 2),
                    'year' => substr($token, -2),
                    'begin' => $begin,
                    'end' => $end,
                ];
            }
            if ($tokenLen >= 6) {
                // 4 digit year prefix (199912)
                $candidates1[] = [
                    'daymonth' => substr($token, 4),
                    'year' => substr($token, 0, 4),
                    'begin' => $begin,
                    'end' => $end,
                ];
                // 4 digit year suffix (121999)
                $candidates1[] = [
                    'daymonth' => substr($token, 0, $tokenLen - 4),
                    'year' => substr($token, -4),
                    'begin' => $begin,
                    'end' => $end,
                ];
            }
            // Create day/month candidates from years.
            $candidates2 = [];
            foreach ($candidates1 as $candidate) {
                switch (strlen($candidate['daymonth'])) {
                    case 2: // ex. 1 1 97
                        $candidates2[] = [
                            'day' => $candidate['daymonth'][0],
                            'month' => $candidate['daymonth'][1],
                            'year' => $candidate['year'],
                            'begin' => $candidate['begin'],
                            'end' => $candidate['end'],
                        ];

                        break;
                    case 3: // ex. 11 1 97 or 1 11 97
                        $candidates2[] = [
                            'day' => substr($candidate['daymonth'], 0, 2),
                            'month' => substr($candidate['daymonth'], 2),
                            'year' => $candidate['year'],
                            'begin' => $candidate['begin'],
                            'end' => $candidate['end'],
                        ];
                        $candidates2[] = [
                            'day' => substr($candidate['daymonth'], 0, 1),
                            'month' => substr($candidate['daymonth'], 1, 3),
                            'year' => $candidate['year'],
                            'begin' => $candidate['begin'],
                            'end' => $candidate['end'],
                        ];

                        break;
                    case 4: // ex. 11 11 97
                        $candidates2[] = [
                            'day' => substr($candidate['daymonth'], 0, 2),
                            'month' => substr($candidate['daymonth'], 2, 4),
                            'year' => $candidate['year'],
                            'begin' => $candidate['begin'],
                            'end' => $candidate['end'],
                        ];

                        break;
                }
            }
            // Reject invalid candidates
            foreach ($candidates2 as $candidate) {
                $day = (int) $candidate['day'];
                $month = (int) $candidate['month'];
                $year = (int) $candidate['year'];

                $date = static::checkDate($day, $month, $year);
                if (false === $date) {
                    continue;
                }
                list($day, $month, $year) = $date;

                $dateMatches[] = [
                    'begin' => $candidate['begin'],
                    'end' => $candidate['end'],
                    'token' => substr($password, $begin, $begin + $end - 1),
                    'separator' => '',
                    'day' => $day,
                    'month' => $month,
                    'year' => $year,
                ];
            }
        }

        return $dateMatches;
    }
1048226
private static ArrayList<DateMatch> matchDatesWithoutSeparator(Configuration configuration, String password)
    {

        // Initialize the list of matching dates
        ArrayList<DateMatch> dateMatches = new ArrayList<>();

        // Create all possible subsequences of the password
        for (int start = 0; start < password.length(); start++)
        {
            for (int end = start + 4; end <= password.length(); end++)
            {

                // Get the subsequence
                String passwordChunk = password.substring(start, end);

                // Quick verfication that it is made of numbers
                if (DATE_WITHOUT_SEPARATOR.matcher(passwordChunk).find())
                {

                    // Extract the possible combinaison of dateAndMonth/year from the
                    // subsequence (eg: 121234 => 1212/34 and 12/1234)
                    ArrayList<PartialDateSplit> possiblePartialSplit = new ArrayList<>();
                    int chunkLength = passwordChunk.length();
                    if (chunkLength <= 6)
                    {
                        // start with a 2 digits year
                        possiblePartialSplit.add(new PartialDateSplit(
                                passwordChunk.substring(2),
                                passwordChunk.substring(0, 2)
                        ));
                        // end with a 2 digits year
                        possiblePartialSplit.add(new PartialDateSplit(
                                passwordChunk.substring(0, chunkLength - 2),
                                passwordChunk.substring(chunkLength - 2, chunkLength)
                        ));
                    }
                    if (chunkLength >= 6)
                    {
                        // start with a 4 digits year
                        possiblePartialSplit.add(new PartialDateSplit(
                                passwordChunk.substring(4),
                                passwordChunk.substring(0, 4)
                        ));
                        // end with a 4 digits year
                        possiblePartialSplit.add(new PartialDateSplit(
                                passwordChunk.substring(0, chunkLength - 4),
                                passwordChunk.substring(chunkLength - 4, chunkLength)
                        ));
                    }

                    // For each dateAndMonth/year extract the different possible full date
                    // (eg: 123/1998 => 1/23/1998 and 12/3/1998)
                    ArrayList<FullDateSplit> possibleFullSplit = new ArrayList<>();
                    for (PartialDateSplit split : possiblePartialSplit)
                    {
                        int dateAndMonthLength = split.dateAndMonth.length();
                        if (dateAndMonthLength == 2)
                        {
                            possibleFullSplit.add(new FullDateSplit(
                                    split.dateAndMonth.substring(0, 1),
                                    split.dateAndMonth.substring(1, 2),
                                    split.year
                            ));
                        }
                        else if (dateAndMonthLength == 3)
                        {
                            possibleFullSplit.add(new FullDateSplit(
                                    split.dateAndMonth.substring(0, 1),
                                    split.dateAndMonth.substring(1, 3),
                                    split.year
                            ));
                            possibleFullSplit.add(new FullDateSplit(
                                    split.dateAndMonth.substring(0, 2),
                                    split.dateAndMonth.substring(2, 3),
                                    split.year
                            ));
                        }
                        else if (dateAndMonthLength == 4)
                        {
                            possibleFullSplit.add(new FullDateSplit(
                                    split.dateAndMonth.substring(0, 2),
                                    split.dateAndMonth.substring(2, 4),
                                    split.year
                            ));
                        }
                    }

                    // Add to the final date list all the valid dates
                    for (FullDateSplit split : possibleFullSplit)
                    {
                        ValidDateSplit vSplit = isDateValid(split.date, split.month, split.year);
                        if (vSplit != null)
                        {
                            dateMatches.add(new DateMatch(passwordChunk, configuration, vSplit.date, vSplit.month, vSplit.year, "", start, end - 1));
                        }
                    }

                }
            }
        }

        return dateMatches;

    }
896173
public function hash(string $password): string
    {
        if ('' === $password) {
            throw EmptyPasswordException::create();
        }

        return password_hash($password, PASSWORD_DEFAULT);
    }
1042442
public function ExtractDistinctValues($array) {
        foreach ($array as $key => $value) {
            $valueIsArray = is_array($value);
            $valueIsAlreadyExtracted = in_array($value, $this->List);
            $keyIsExtracted = in_array($key, $this->List);
            if (!$valueIsArray && !$valueIsAlreadyExtracted && !RegexHelper::Init($value)->StringContainsWhiteSpace()) {
                array_push($this->List, $value);
            }
            if (!$keyIsExtracted && is_string($key) && !RegexHelper::Init($key)->StringContainsWhiteSpace()) {
                array_push($this->List, $key);
            }
            if ($valueIsArray) {
                $this->ExtractDistinctValues($value);
            }
        }
        return $this;
    }
1313940
public function parse_position($string)
    {

        if (empty($string)) return array();

        // get the timestamp for this year
        $time_array = array(
            'range'    => '*',
            'interval' => false
        );

        if ($string == '*') {
            return $time_array;
        } else if (preg_match('/^(\d{4})$/', $string)) {
            $time_array['range'] = $string;

            return $time_array;
        } else {
            $time_array['range'] = array();
            switch (true) {
                // first check if it's a list
                case (strpos($string, ',') !== false) :
                    $multi_pos = explode(',', $string);
                    $interval  = false;
                    foreach ($multi_pos as $pos) {
                        switch (true) {
                            // get the interval first than proceed to the next
                            case (($pos_pos = strpos($pos, '/')) !== false) :
                                $interval = explode('/', $pos);
                                $pos      = substr($pos, 0, -(strlen($pos) - $pos_pos));
                            // check the ranges
                            default :
                                $time_array['range'][] = array(
                                    'range'    => $pos,
                                    'interval' => $interval[1]
                                );
                                $interval              = false;
                                break;

                        }
                    }
                    break;
                // check if it's a range
                case (strpos($string, '-') !== false) :
                    // get the interval first than proceed
                    if (($pos_pos = strpos($string, '/')) !== false) {
                        $interval               = explode('/', $string);
                        $time_array['interval'] = $interval[1];
                        $string                 = substr($string, 0, -$pos_pos);
                    }
                    $time_array['range'] = $string;
                    break;
                // check if it's an interval
                case (strpos($string, '/') !== false) :
                    $multi_pos              = explode('/', $string);
                    $time_array['range']    = $multi_pos[0];
                    $time_array['interval'] = $multi_pos[1];
                    break;
            }
        }

        return $time_array;
    }
399894
protected function demergePasswordAndSalt($mergedPasswordSalt)
    {
        if (empty($mergedPasswordSalt)) {
            return array('', '');
        }

        $password = $mergedPasswordSalt;
        $salt = '';
        $saltBegins = strrpos($mergedPasswordSalt, '{');

        if (false !== $saltBegins && $saltBegins + 1 < strlen($mergedPasswordSalt)) {
            $salt = substr($mergedPasswordSalt, $saltBegins + 1, -1);
            $password = substr($mergedPasswordSalt, 0, $saltBegins);
        }

        return array($password, $salt);
    }
456659
public function getExcludedDates()
    {
        $dates = [];
        foreach ($this->getValue('excludedDates') as $date => $v) {
            $d = \DateTime::createFromFormat('U', $date);

            if ($tz = $this->getTimeZone()) {
                $d->setTimezone($tz);
            }

            $dates[] = $d;
        }

        return $dates;
    }
78900
public function checkPassword($password)
    {
        $encryptor = PasswordEncryptor::create_for_algorithm($this->PasswordEncryption);
        return $encryptor->check($this->Password, $password, $this->Salt, $this->Member());
    }
247829
private function getDatesToInvalidateFromString($dates)
    {
        $toInvalidate = array();
        $invalidDates = array();

        $dates = explode(',', trim($dates));
        $dates = array_unique($dates);

        foreach ($dates as $theDate) {
            $theDate = trim($theDate);
            try {
                $date = Date::factory($theDate);
            } catch (\Exception $e) {
                $invalidDates[] = $theDate;
                continue;
            }

            if ($date->toString() == $theDate) {
                $toInvalidate[] = $date;
            } else {
                $invalidDates[] = $theDate;
            }
        }

        return array($toInvalidate, $invalidDates);
    }
478461
public function escape($data)
    {
        if ($data instanceof Date) {
            return [$data->format(), true];
        } elseif ($data instanceof \DateTime || $data instanceof \DateTimeImmutable) {
            return [gmdate('Y-m-d H:i:s', $data->getTimestamp()), true];
        } elseif (is_null($data)) {
            return ['NULL', false];
        } elseif (is_array($data)) {
            if (array_keys($data) !== range(0, count($data) - 1)) {
                throw new \InvalidArgumentException(sprintf(
                    "Can't escape associative array with data '%s'",
                    json_encode($data)
                ));
            }

            $return = [];
            foreach ($data as $current) {
                $return[] = $this->escape($current);
            }

            return [implode(', ', $return), false];
        } elseif (is_string($data) && ctype_digit($data) && substr($data, 0, 1) == '0') {
            // phone number starting with a 0x xxx xxx
            return [$data, true];
        } elseif (is_numeric($data) && substr((string) $data, 0, 1) != '+' && substr((string) $data, 0, 1) != '-') {
            // @see http://php.net/manual/en/function.is-numeric.php
            // Thus +0123.45e6 is a valid numeric value : we don't want
            return [$data, true];
        } elseif (is_bool($data)) {
            return [$data === true ? 'TRUE' : 'FALSE', false];
        } else {
            return [$data, true];
        }
    }
288161
public function passwordRehash($password)
    {
        if (password_needs_rehash(
            $password,
            $this->config[ 'password' ][ 'algorithm' ],
            $this->config[ 'password' ][ 'options' ]
        )) {
            return $this->passwordHash($password);
        }

        return $password;
    }
412120
protected function _analyze($password)
    {
        // Reset the class
        $this->_password = $password;
        $this->_score = 0;
        $this->_length = strlen($password);
        $this->_tokens = array ();
        $this->_tokenCounts = array (
            self::CLASS_LETTER => 0,
            self::CLASS_UPPER => 0,
            self::CLASS_LOWER => 0,
            self::CLASS_NUMBER => 0,
            self::CLASS_SYMBOL => 0
        );
        $this->_tokenIndices = array (
            self::CLASS_LETTER => array (),
            self::CLASS_UPPER => array (),
            self::CLASS_LOWER => array (),
            self::CLASS_NUMBER => array (),
            self::CLASS_SYMBOL => array ()
        );

        $this->_parseTokens();
    }
1333754
public function lmPasswordHash($password = null)
    {
        $plain = isset($password) ? $password : $this->password;

        $plain = substr(strtoupper($plain), 0, 14);
        while (strlen($plain) < 14) {
             $plain .= "\0";
        }

        return $this->_desHash(substr($plain, 0, 7)) . $this->_desHash(substr($plain, 7, 7));
    }
865721
protected function parseKeyValuePair($string) {
        list($key, $value) = explode('=', $string);

        $key = trim($key);
        $value = trim($value);

        return [$key, $value];
    }
670964
public function getPostsByDate($date)
    {
        if (false === array_key_exists($date, $this->dateIndex)) {
            return [];
        }

        $postNames = $this->dateIndex[$date];

        return $this->getPostsByName($postNames);
    }
1262235
public function ntPasswordHash($password = null)
    {
        //if (isset($password)) {
        if (!is_null($password)) {
            return pack('H*',hash('md4', $this->str2unicode($password)));
        } else {
            return pack('H*',hash('md4', $this->str2unicode($this->password)));
        }
    }
535651
static protected function regex($date)
    {
      if(!preg_match('/^' . self::PATTERN . '$/', $date, $matches))
        throw new InvalidArgumentException(__METHOD__ . '; Invalid date, no match with pattern (' . $date . ')');
        
      return $matches;
    }