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
31abstract class ModeleGenPassword
32{
36 public $id;
37
41 public $version;
42
46 public $picto = 'generic';
47
53 public $WithoutAmbi = 0;
54
58 public $error = '';
59
63 public $db;
64
68 public $conf;
69
73 public $langs;
74
78 public $user;
79
85 public $length;
86
92 public $length2;
93
99 public function isEnabled()
100 {
101 return true;
102 }
103
109 public function getDescription()
110 {
111 global $langs;
112 return $langs->trans("NoDescription");
113 }
114
120 public function getExample()
121 {
122 global $langs;
123 $langs->load("bills");
124 return $langs->trans("NoExample");
125 }
126
132 public function getNewGeneratedPassword()
133 {
134 global $langs;
135 return $langs->trans("NotAvailable");
136 }
137
145 public function validatePassword($password)
146 {
147 return 1;
148 }
149
166 public static function loadAndInstantiate($id, $db, $conf, $langs, $user)
167 {
168 if (empty($id)) {
169 return null;
170 }
171
172 $classname = 'modGeneratePass'.ucfirst($id);
173
174 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
175 foreach ($dirmodels as $reldir) {
176 $file = dol_buildpath($reldir.'core/modules/security/generate/').$classname.'.class.php';
177 if (is_file($file)) {
178 require_once $file;
179 if (class_exists($classname)) {
180 return new $classname($db, $conf, $langs, $user);
181 }
182 }
183 }
184
185 return null;
186 }
187}
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.