-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
executable file
·71 lines (63 loc) · 2.46 KB
/
index.php
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
use Kirby\Cms\Page;
Kirby::plugin('pechente/kirby-password-guard', [
'templates' => [
'password-guard' => __DIR__ . '/templates/password-guard.php',
],
'snippets' => [
'panel-icon' => __DIR__ . '/snippets/panel-icon.php',
],
'routes' => [
[
'pattern' => 'password-guard',
'language' => '*',
'method' => 'POST',
'action' => function () {
$password = get('password');
$hashedPassword = password_hash($password, PASSWORD_BCRYPT);
$session = kirby()->session();
$session->set('kirby-password-guard.password-hash', $hashedPassword);
$redirect = get('redirect');
kirby()->response()->redirect($redirect);
}
],
[
'pattern' => option('pechente.kirby-password-guard.pattern', '(:all)'),
'method' => 'GET',
'action' => function (string $uid) {
if (
option('pechente.kirby-password-guard.enabled') === false ||
!option('pechente.kirby-password-guard.password') ||
kirby()->user()
) {
$this->next();
}
$passwordIncorrect = false;
// check session for password
$session = kirby()->session();
$hash = $session->get('kirby-password-guard.password-hash');
$password = option('pechente.kirby-password-guard.password');
// Display the page if the password is correct
if ($hash) {
if (password_verify($password, $hash)) {
$this->next();
} else {
$passwordIncorrect = true;
kirby()->session()->remove('kirby-password-guard.password-hash');
}
}
// Render the Password Entry Page if it's not correct
$passwordPage = new Page([
'slug' => 'password-guard',
'template' => 'password-guard',
'content' => [
'title' => 'Password Guard',
'redirect' => url($uid),
'passwordIncorrect' => $passwordIncorrect
]
]);
return $passwordPage->render();
}
]
],
]);