dolibarr  9.0.0
modGeneratePassStandard.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  * or see http://www.gnu.org/
17  */
18 
25 require_once DOL_DOCUMENT_ROOT .'/core/modules/security/generate/modules_genpassword.php';
26 
27 
33 {
37  public $id;
38 
39  public $length;
40 
44  public $db;
45 
46  public $conf;
47  public $lang;
48  public $user;
49 
50 
59  function __construct($db, $conf, $langs, $user)
60  {
61  $this->id = "standard";
62  $this->length = 8;
63 
64  $this->db=$db;
65  $this->conf=$conf;
66  $this->langs=$langs;
67  $this->user=$user;
68  }
69 
75  function getDescription()
76  {
77  global $langs;
78  return $langs->trans("PasswordGenerationStandard");
79  }
80 
86  function getExample()
87  {
88  return $this->getNewGeneratedPassword();
89  }
90 
97  {
98  // start with a blank password
99  $password = "";
100 
101  // define possible characters
102  $possible = "0123456789bcdfghjkmnpqrstvwxyz";
103 
104  // set up a counter
105  $i = 0;
106 
107  // add random characters to $password until $length is reached
108  while ($i < $this->length)
109  {
110 
111  // pick a random character from the possible ones
112  $char = substr($possible, mt_rand(0, dol_strlen($possible)-1), 1);
113 
114  // we don't want this character if it's already in the password
115  if (!strstr($password, $char))
116  {
117  $password .= $char;
118  $i++;
119  }
120  }
121 
122  // done!
123  return $password;
124  }
125 
132  function validatePassword($password)
133  {
134  if (dol_strlen($password) < $this->length) return 0;
135  return 1;
136  }
137 }
138 
Parent class for password rules/management modules.
conf($dolibarr_main_document_root)
Load conf file (file must exists)
Definition: inc.php:292
__construct($db, $conf, $langs, $user)
Constructor.
validatePassword($password)
Validate a password.
getNewGeneratedPassword()
Build new password.
Class to generate a password according to a dolibarr standard rule (8 random chars) ...
getExample()
Return an example of password generated by this module.
$conf db user
Definition: repair.php:104
getDescription()
Return description of module.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.