Skip to content

Commit

Permalink
Create custom PasswordExposedChecker object and set cache directory t…
Browse files Browse the repository at this point in the history
…o Laravel storage path
  • Loading branch information
DivineOmega committed Nov 15, 2018
1 parent 0d27754 commit 1e5adb7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
39 changes: 39 additions & 0 deletions src/Factories/PasswordExposedCheckerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace DivineOmega\LaravelPasswordExposedValidationRule\Factories;

use DivineOmega\DOFileCachePSR6\CacheItemPool;
use DivineOmega\PasswordExposed\PasswordExposedChecker;

/**
* Class PasswordExposedCheckerFactory
* @package DivineOmega\LaravelPasswordExposedValidationRule\Factories
*/
class PasswordExposedCheckerFactory
{
/**
* Creates and returns an instance of PasswordExposedChecker.
*
* @return PasswordExposedChecker
*/
public function instance()
{
$cache = new CacheItemPool();

$cache->changeConfig([
'cacheDirectory' => $this->getCacheDirectory(),
]);

return new PasswordExposedChecker(null, $cache);
}

/**
* Gets the directory to store the cache files.
*
* @return string
*/
private function getCacheDirectory()
{
return storage_path('password-exposed-cache/');
}
}
18 changes: 17 additions & 1 deletion src/PasswordExposed.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,35 @@

namespace DivineOmega\LaravelPasswordExposedValidationRule;

use DivineOmega\LaravelPasswordExposedValidationRule\Factories\PasswordExposedCheckerFactory;
use DivineOmega\PasswordExposed\PasswordExposedChecker;
use DivineOmega\PasswordExposed\PasswordStatus;
use Illuminate\Contracts\Validation\Rule;

/**
* Class PasswordExposed
* @package DivineOmega\LaravelPasswordExposedValidationRule
*/
class PasswordExposed implements Rule
{
/**
* @var PasswordExposedChecker
*/
private $passwordExposedChecker;
/**
* @var string
*/
private $message = 'The :attribute has been exposed in a data breach.';

/**
* PasswordExposed constructor.
* @param PasswordExposedChecker|null $passwordExposedChecker
*/
public function __construct(PasswordExposedChecker $passwordExposedChecker = null)
{
if (!$passwordExposedChecker) {
$passwordExposedChecker = new PasswordExposedChecker();
$factory = new PasswordExposedCheckerFactory();
$passwordExposedChecker = $factory->instance();
}

$this->passwordExposedChecker = $passwordExposedChecker;
Expand Down

0 comments on commit 1e5adb7

Please sign in to comment.