-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_device_security.php
More file actions
53 lines (41 loc) · 1.39 KB
/
multi_device_security.php
File metadata and controls
53 lines (41 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* @copyright ©2025 Maatify.dev
* @Library maatify/security-guard
* @Project maatify:security-guard
* @author Mohamed Abdulalim (megyptm) <mohamed@maatify.dev>
* @since 2025-12-11 01:36
* @see https://www.maatify.dev Maatify.dev
* @link https://github.com/Maatify/security-guard view Project on GitHub
* @note Distributed in the hope that it will be useful - WITHOUT WARRANTY.
*/
declare(strict_types=1);
/**
* PRO Example 4:
* Multi-device login simulation for the same subject.
*/
use Maatify\SecurityGuard\DTO\LoginAttemptDTO;
$guard = require __DIR__ . '/../bootstrap.php';
$subject = "mohamed@example.com";
$config = $guard->getConfig();
$devices = [
"Chrome on Windows" => "192.168.20.11",
"Safari on macOS" => "192.168.20.12",
"Firefox on Linux" => "192.168.20.13",
"Mobile iOS" => "192.168.20.14",
];
echo "\n===== MULTI DEVICE SECURITY =====\n\n";
foreach ($devices as $device => $ip) {
$attempt = LoginAttemptDTO::now(
ip : $ip,
subject : $subject,
resetAfter: $config->windowSeconds(),
userAgent : $device,
context : ['device' => $device]
);
$result = $guard->handleAttempt($attempt, false);
echo "{$device} → failure count = {$result}\n";
if ($guard->isBlocked($ip, $subject)) {
echo "🚫 BLOCKED device {$device}\n";
}
}