dbxapp 4.1.3
CMS, Shop, Workflows und modulare Geschäftsanwendungen
Loading...
Searching...
No Matches
login_password_reset_test.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5require_once dirname(__DIR__) . '/include/login.class.php';
6
7use dbx\dbxLogin\login;
8
9function login_password_reset_assert(bool $condition, string $message): void
10{
11 if (!$condition) {
12 throw new RuntimeException($message);
13 }
14}
15
16$class = new ReflectionClass(login::class);
17$login = $class->newInstanceWithoutConstructor();
18$resetRequired = $class->getMethod('password_reset_required');
19$passwordErrors = $class->getMethod('password_change_errors');
20
22 'uname' => 'admin',
23 'settings' => '{}',
24);
26 $resetRequired->invoke($login, $defaultAdmin, '123456') === true,
27 'admin/123456 muss unabhängig von älteren DB3-Einstellungen einen Passwortwechsel erzwingen.'
28);
30 $resetRequired->invoke($login, $defaultAdmin, 'individuell') === false,
31 'Ein individueller Admin-Zugang darf nicht als Standardpasswort gelten.'
32);
34 $resetRequired->invoke(
35 $login,
36 array(
37 'uname' => 'user',
38 'settings' => json_encode(array('password_reset_required' => 1)),
39 ),
40 'beliebig'
41 ) === true,
42 'Das vorhandene Kennzeichen password_reset_required muss weiter unterstützt werden.'
43);
44
45$currentHash = password_hash('123456', PASSWORD_DEFAULT);
47 isset($passwordErrors->invoke(
48 $login,
49 '123456',
50 '123456',
52 )['password_new']),
53 'Das unsichere Initialpasswort darf nicht erneut gespeichert werden.'
54);
56 isset($passwordErrors->invoke(
57 $login,
58 'Sicher-2026!Passwort',
59 'Anders-2026!Passwort',
61 )['password_repeat']),
62 'Abweichende Passwortwiederholungen müssen abgelehnt werden.'
63);
65 $passwordErrors->invoke(
66 $login,
67 'Sicher-2026!Passwort',
68 'Sicher-2026!Passwort',
70 ) === array(),
71 'Ein starkes, neues Passwort muss akzeptiert werden.'
72);
74 $passwordErrors->invoke(
75 $login,
76 'Ab1!xy',
77 'Ab1!xy',
79 6
80 ) === array(),
81 'Eine konfigurierte Mindestlänge von 6 Zeichen muss bei erfüllten Qualitätsregeln akzeptiert werden.'
82);
84 isset($passwordErrors->invoke(
85 $login,
86 'Ab1!x',
87 'Ab1!x',
89 6
90 )['password_new']),
91 'Ein Passwort unterhalb der konfigurierten Mindestlänge muss abgelehnt werden.'
92);
94 $login,
95 'abc',
96 'abc',
98 6
99);
101 str_contains((string)($detailedErrors['password_new'] ?? ''), 'mindestens 6 Zeichen')
102 && str_contains((string)($detailedErrors['password_new'] ?? ''), 'ein Großbuchstabe')
103 && str_contains((string)($detailedErrors['password_new'] ?? ''), 'eine Zahl')
104 && str_contains((string)($detailedErrors['password_new'] ?? ''), 'ein Sonderzeichen'),
105 'Die Fehlermeldung muss alle noch nicht erfüllten Passwortkriterien einzeln nennen.'
106);
107
108$source = (string)file_get_contents(dirname(__DIR__) . '/include/login.class.php');
109$policySource = (string)file_get_contents(
110 dirname(__DIR__, 3) . '/include/dbxPasswordPolicy.class.php'
111);
112$template = (string)file_get_contents(
113 dirname(__DIR__) . '/tpl/htm/form-password-change.htm'
114);
116 str_contains($source, 'pending_password_reset')
117 && str_contains($source, "unset(\$settings['password_reset_required'])")
118 && str_contains($source, 'password_hash($password, PASSWORD_DEFAULT)')
119 && str_contains($source, 'dbx()->login($uid)'),
120 'Der erzwungene Passwortwechsel ist nicht vollständig abgeschlossen.'
121);
122$statusCheck = strpos($source, "(string)(\$rec['status'] ?? '') === '0'");
123$resetCheck = strpos($source, '$this->password_reset_required($rec, $pass)');
125 $statusCheck !== false
126 && $resetCheck !== false
128 'Gesperrte Benutzer dürfen nicht über den initialen Passwortwechsel freigeschaltet werden.'
129);
131 str_contains($template, '{obj:password_new}')
132 && str_contains($template, '{obj:password_repeat}')
133 && str_contains($template, '{password_min_length}')
134 && str_contains($template, 'data-password-rule="length"')
135 && str_contains($template, 'data-password-rule="match"')
136 && str_contains($template, 'bi-x-circle-fill')
137 && str_contains($template, 'Ein neues sicheres Passwort festlegen')
138 && str_contains($source, 'Für diesen Zugang ist ein neues persönliches Passwort erforderlich.')
139 && str_contains($policySource, 'Noch nicht erfüllt:')
140 && str_contains($source, '\\dbxPasswordPolicy::errors(')
141 && str_contains($template, 'Neues Passwort speichern'),
142 'Das Passwortänderungsformular ist unvollständig.'
143);
144
145echo "OK forced password change and legacy admin compatibility\n";
login_password_reset_assert(bool $condition, string $message)