Skip to content

Commit 1e5adb7

Browse files
committed
Create custom PasswordExposedChecker object and set cache directory to Laravel storage path
1 parent 0d27754 commit 1e5adb7

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace DivineOmega\LaravelPasswordExposedValidationRule\Factories;
4+
5+
use DivineOmega\DOFileCachePSR6\CacheItemPool;
6+
use DivineOmega\PasswordExposed\PasswordExposedChecker;
7+
8+
/**
9+
* Class PasswordExposedCheckerFactory
10+
* @package DivineOmega\LaravelPasswordExposedValidationRule\Factories
11+
*/
12+
class PasswordExposedCheckerFactory
13+
{
14+
/**
15+
* Creates and returns an instance of PasswordExposedChecker.
16+
*
17+
* @return PasswordExposedChecker
18+
*/
19+
public function instance()
20+
{
21+
$cache = new CacheItemPool();
22+
23+
$cache->changeConfig([
24+
'cacheDirectory' => $this->getCacheDirectory(),
25+
]);
26+
27+
return new PasswordExposedChecker(null, $cache);
28+
}
29+
30+
/**
31+
* Gets the directory to store the cache files.
32+
*
33+
* @return string
34+
*/
35+
private function getCacheDirectory()
36+
{
37+
return storage_path('password-exposed-cache/');
38+
}
39+
}

src/PasswordExposed.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,35 @@
22

33
namespace DivineOmega\LaravelPasswordExposedValidationRule;
44

5+
use DivineOmega\LaravelPasswordExposedValidationRule\Factories\PasswordExposedCheckerFactory;
56
use DivineOmega\PasswordExposed\PasswordExposedChecker;
67
use DivineOmega\PasswordExposed\PasswordStatus;
78
use Illuminate\Contracts\Validation\Rule;
89

10+
/**
11+
* Class PasswordExposed
12+
* @package DivineOmega\LaravelPasswordExposedValidationRule
13+
*/
914
class PasswordExposed implements Rule
1015
{
16+
/**
17+
* @var PasswordExposedChecker
18+
*/
1119
private $passwordExposedChecker;
20+
/**
21+
* @var string
22+
*/
1223
private $message = 'The :attribute has been exposed in a data breach.';
1324

25+
/**
26+
* PasswordExposed constructor.
27+
* @param PasswordExposedChecker|null $passwordExposedChecker
28+
*/
1429
public function __construct(PasswordExposedChecker $passwordExposedChecker = null)
1530
{
1631
if (!$passwordExposedChecker) {
17-
$passwordExposedChecker = new PasswordExposedChecker();
32+
$factory = new PasswordExposedCheckerFactory();
33+
$passwordExposedChecker = $factory->instance();
1834
}
1935

2036
$this->passwordExposedChecker = $passwordExposedChecker;

0 commit comments

Comments
 (0)