dbxapp 4.1.3
CMS, Shop, Workflows und modulare Geschäftsanwendungen
Loading...
Searching...
No Matches
dbxPasswordPolicy.class.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
9{
10 public static function minimumLength(?int $configured = null): int
11 {
12 if ($configured === null && function_exists('dbx')) {
13 $configured = (int)dbx()->get_config(
14 'dbx',
15 'password_min_length',
16 6
17 );
18 }
19 $configured = $configured ?? 6;
20 return max(6, min(128, $configured > 0 ? $configured : 6));
21 }
22
26 public static function missingCriteria(
27 string $password,
28 ?int $minimumLength = null
29 ): array {
30 $minimumLength = self::minimumLength($minimumLength);
31 $length = function_exists('mb_strlen')
32 ? mb_strlen($password, 'UTF-8')
33 : strlen($password);
34 $missing = array();
35 if ($length < $minimumLength) {
36 $missing[] = 'mindestens ' . $minimumLength . ' Zeichen';
37 }
38 if (preg_match('/[A-Z]/', $password) !== 1) {
39 $missing[] = 'ein Großbuchstabe';
40 }
41 if (preg_match('/[a-z]/', $password) !== 1) {
42 $missing[] = 'ein Kleinbuchstabe';
43 }
44 if (preg_match('/[0-9]/', $password) !== 1) {
45 $missing[] = 'eine Zahl';
46 }
47 if (preg_match('/[^A-Za-z0-9]/', $password) !== 1) {
48 $missing[] = 'ein Sonderzeichen';
49 }
50 return $missing;
51 }
52
53 public static function missingMessage(
54 array $missing,
55 ?int $minimumLength = null
56 ): string {
57 if ($missing === array()) {
58 return '';
59 }
60 $minimumLength = self::minimumLength($minimumLength);
61 return 'Noch nicht erfüllt: ' . implode(', ', $missing) . '.'
62 . ($minimumLength < 12
63 ? ' Empfohlen sind insgesamt 12 oder mehr Zeichen.'
64 : '');
65 }
66
70 public static function errors(
71 string $password,
72 string $repeat,
73 string $currentHash = '',
74 ?int $minimumLength = null
75 ): array {
76 $minimumLength = self::minimumLength($minimumLength);
77 $errors = array();
78 if (!hash_equals($password, $repeat)) {
79 $errors['repeat'] = 'Die beiden Passwörter stimmen nicht überein.';
80 }
81 $missing = self::missingCriteria($password, $minimumLength);
82 if ($missing !== array()) {
83 $errors['password'] = self::missingMessage(
85 $minimumLength
86 );
87 } elseif ($currentHash !== ''
88 && password_get_info($currentHash)['algoName'] !== 'unknown'
89 && password_verify($password, $currentHash)
90 ) {
91 $errors['password'] = 'Das neue Passwort muss sich vom bisherigen Passwort unterscheiden.';
92 }
93 return $errors;
94 }
95}
Zentrale Passwortvorgaben für Installation, Login und Profilbearbeitung.
static missingCriteria(string $password, ?int $minimumLength=null)
static missingMessage(array $missing, ?int $minimumLength=null)
static errors(string $password, string $repeat, string $currentHash='', ?int $minimumLength=null)
static minimumLength(?int $configured=null)
if($out !==$expected) $missing
if(!defined( 'IMG_WEBP')) define( 'IMG_WEBP'
DBX schema administration.