Skip to content

Commit

Permalink
Validator password history check logic optimisations.
Browse files Browse the repository at this point in the history
  • Loading branch information
allebb committed Feb 8, 2020
1 parent c5938f6 commit 592c97d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
35 changes: 17 additions & 18 deletions lib/Support/Validator.php
Expand Up @@ -115,8 +115,8 @@ public function validate(Plexity $configuration)

/**
* Checks the minimum length requirement.
* @throws ValidationException
* @return void
* @throws ValidationException
*/
public function checkMinimumLength()
{
Expand All @@ -129,8 +129,8 @@ public function checkMinimumLength()

/**
* Checks the minimum maximum length requirement.
* @throws ValidationException
* @return void
* @throws ValidationException
*/
public function checkMaximumLength()
{
Expand All @@ -143,8 +143,8 @@ public function checkMaximumLength()

/**
* Checks the lowercase character(s) requirement.
* @throws ValidationException
* @return void
* @throws ValidationException
*/
public function checkLowerCase()
{
Expand All @@ -157,8 +157,8 @@ public function checkLowerCase()

/**
* Checks the upper case character(s) requirement.
* @throws ValidationException
* @return void
* @throws ValidationException
*/
public function checkUpperCase()
{
Expand All @@ -171,8 +171,8 @@ public function checkUpperCase()

/**
* Checks the numeric character(s) requirement.
* @throws ValidationException
* @return void
* @throws ValidationException
*/
public function checkNumericCharacters()
{
Expand All @@ -185,8 +185,8 @@ public function checkNumericCharacters()

/**
* Checks the special character(s) requirement.
* @throws ValidationException
* @return void
* @throws ValidationException
*/
public function checkSpecialCharacters()
{
Expand All @@ -199,8 +199,8 @@ public function checkSpecialCharacters()

/**
* Validates if a string is not in a array (password history database).
* @throws ValidationException
* @return void
* @throws ValidationException
*/
public function checkNotIn()
{
Expand All @@ -210,15 +210,11 @@ public function checkNotIn()
}

if ($this->configuration->rules()->get(Plexity::RULE_NOT_IN) instanceof PasswordHistoryInterface) {
if ($this->validateNotInPasswordHistoryImplementation()) {
throw new ValidationException('The string exists in the list of disallowed values requirements.');
}
$this->validateNotInPasswordHistoryImplementation();
}

if (is_array($this->configuration->rules()->get(Plexity::RULE_NOT_IN)) && count($this->configuration->rules()->get(Plexity::RULE_NOT_IN)) > 0) {
if (!$this->validateNotInArray()) {
throw new ValidationException('The string exists in the list of disallowed values requirements.');
}
$this->validateNotInArray();
}

}
Expand Down Expand Up @@ -305,24 +301,27 @@ private function validateLengthMax()

/**
* Validates the not_in requirements against a simple array.
* @return boolean
* @return void
* @throws ValidationException
*/
private function validateNotInArray()
{
if (in_array($this->configuration->checkString(),
(array)$this->configuration->rules()->get(Plexity::RULE_NOT_IN))) {
return false;
throw new ValidationException('The string exists in the list of disallowed values requirements.');
}
return true;
}

/**
* Validates the not_in requirements against an implementation of PasswordHistoryInterface.
* @return boolean
* @return void
* @throws ValidationException
*/
private function validateNotInPasswordHistoryImplementation()
{
return ($this->configuration->rules()->get(Plexity::RULE_NOT_IN))->checkHistory($this->configuration->checkString());
if (($this->configuration->rules()->get(Plexity::RULE_NOT_IN))->checkHistory($this->configuration->checkString())) {
throw new ValidationException('The string exists in the list of disallowed values requirements.');
}
}

/**
Expand Down
1 change: 0 additions & 1 deletion tests/PlexityTest.php
Expand Up @@ -2,7 +2,6 @@

namespace Ballen\Plexity\Tests;

use Ballen\Plexity\Exceptions\ValidationException;
use Ballen\Plexity\Plexity;
use Ballen\Plexity\Tests\Implementations\MD5PasswordHistoryStore;

Expand Down

0 comments on commit 592c97d

Please sign in to comment.