dolibarr 25.0.0-alpha
modules_genpassword.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 */
20
27require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; // For isPasswordGenerationNoneForbidden()
28
29
33abstract class ModeleGenPassword
34{
38 public $id;
39
43 public $version;
44
48 public $picto = 'generic';
49
55 public $WithoutAmbi = 0;
56
60 public $error = '';
61
65 public $db;
66
70 public $conf;
71
75 public $langs;
76
80 public $user;
81
87 public $length;
88
94 public $length2;
95
101 public function isEnabled()
102 {
103 return true;
104 }
105
111 public function getDescription()
112 {
113 global $langs;
114 return $langs->trans("NoDescription");
115 }
116
122 public function getExample()
123 {
124 global $langs;
125 $langs->load("bills");
126 return $langs->trans("NoExample");
127 }
128
134 public function getNewGeneratedPassword()
135 {
136 global $langs;
137 return $langs->trans("NotAvailable");
138 }
139
147 public function validatePassword($password)
148 {
149 return 1;
150 }
151
168 public static function loadAndInstantiate($id, $db, $conf, $langs, $user)
169 {
170 if (empty($id)) {
171 return null;
172 }
173
174 // The 'none' model applies no rule at all. When it is forbidden (conf.php lock),
175 // transparently fall back to the always-available 'standard' model so an installation still
176 // configured with 'none' enforces a real rule at generation and validation time, without
177 // having to rewrite the stored USER_PASSWORD_GENERATED value.
178 if (strtolower($id) === 'none' && isPasswordGenerationNoneForbidden()) {
179 $id = 'standard';
180 }
181
182 $classname = 'modGeneratePass'.ucfirst($id);
183
184 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
185 foreach ($dirmodels as $reldir) {
186 $file = dol_buildpath($reldir.'core/modules/security/generate/').$classname.'.class.php';
187 if (is_file($file)) {
188 require_once $file;
189 if (class_exists($classname)) {
190 return new $classname($db, $conf, $langs, $user);
191 }
192 }
193 }
194
195 return null;
196 }
197}
Parent class for password rules/management modules.
getDescription()
Return description of module.
static loadAndInstantiate($id, $db, $conf, $langs, $user)
Locate, load and instantiate a password generator/validator model by its id (the value stored in USER...
isEnabled()
Return if a module can be used or not.
validatePassword($password)
Validate a password.
getExample()
Return an example of password generated by this module.
getNewGeneratedPassword()
Build new password.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
isPasswordGenerationNoneForbidden()
Return if the 'none' password generation model (the one that applies no rule at all) is forbidden on ...