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 $position = 50;
49
53 public $picto = 'generic';
54
60 public $WithoutAmbi = 0;
61
65 public $error = '';
66
70 public $db;
71
75 public $conf;
76
80 public $langs;
81
85 public $user;
86
92 public $length;
93
99 public $length2;
100
106 public function isEnabled()
107 {
108 return true;
109 }
110
116 public function getDescription()
117 {
118 global $langs;
119 return $langs->trans("NoDescription");
120 }
121
127 public function getExample()
128 {
129 global $langs;
130 $langs->load("bills");
131 return $langs->trans("NoExample");
132 }
133
139 public function getNewGeneratedPassword()
140 {
141 global $langs;
142 return $langs->trans("NotAvailable");
143 }
144
152 public function validatePassword($password)
153 {
154 return 1;
155 }
156
173 public static function loadAndInstantiate($id, $db, $conf, $langs, $user)
174 {
175 if (empty($id)) {
176 return null;
177 }
178
179 // The 'none' model applies no rule at all. When it is forbidden (conf.php lock),
180 // transparently fall back to the always-available 'standard' model so an installation still
181 // configured with 'none' enforces a real rule at generation and validation time, without
182 // having to rewrite the stored USER_PASSWORD_GENERATED value.
183 if (strtolower($id) === 'none' && isPasswordGenerationNoneForbidden()) {
184 $id = 'standard';
185 }
186
187 $classname = 'modGeneratePass'.ucfirst($id);
188
189 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
190 foreach ($dirmodels as $reldir) {
191 $file = dol_buildpath($reldir.'core/modules/security/generate/').$classname.'.class.php';
192 if (is_file($file)) {
193 require_once $file;
194 if (class_exists($classname)) {
195 return new $classname($db, $conf, $langs, $user);
196 }
197 }
198 }
199
200 return null;
201 }
202}
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 ...