You are here

public function MatchBase::getCardinality in Password Strength 8.2

Get token's symbol space.

Return value

int

File

src/MatchBase.php, line 74

Class

MatchBase

Namespace

Drupal\password_strength

Code

public function getCardinality() {
  if (!is_null($this->cardinality)) {
    return $this->cardinality;
  }
  $lower = $upper = $digits = $symbols = $unicode = 0;

  // Use token instead of password to support bruteforce matches on sub-string
  // of password.
  $chars = str_split($this->token);
  foreach ($chars as $char) {
    $ord = ord($char);
    if ($this
      ->isDigit($ord)) {
      $digits = 10;
    }
    elseif ($this
      ->isUpper($ord)) {
      $upper = 26;
    }
    elseif ($this
      ->isLower($ord)) {
      $lower = 26;
    }
    elseif ($this
      ->isSymbol($ord)) {
      $symbols = 33;
    }
    else {
      $unicode = 100;
    }
  }
  $this->cardinality = $lower + $digits + $upper + $symbols + $unicode;
  return $this->cardinality;
}