dolibarr  7.0.0-beta
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 {
34  var $id;
35  var $length;
36 
37  var $db;
38  var $conf;
39  var $lang;
40  var $user;
41 
42 
51  function __construct($db, $conf, $langs, $user)
52  {
53  $this->id = "standard";
54  $this->length = 8;
55 
56  $this->db=$db;
57  $this->conf=$conf;
58  $this->langs=$langs;
59  $this->user=$user;
60  }
61 
67  function getDescription()
68  {
69  global $langs;
70  return $langs->trans("PasswordGenerationStandard");
71  }
72 
78  function getExample()
79  {
80  return $this->getNewGeneratedPassword();
81  }
82 
89  {
90  // start with a blank password
91  $password = "";
92 
93  // define possible characters
94  $possible = "0123456789bcdfghjkmnpqrstvwxyz";
95 
96  // set up a counter
97  $i = 0;
98 
99  // add random characters to $password until $length is reached
100  while ($i < $this->length)
101  {
102 
103  // pick a random character from the possible ones
104  $char = substr($possible, mt_rand(0, dol_strlen($possible)-1), 1);
105 
106  // we don't want this character if it's already in the password
107  if (!strstr($password, $char))
108  {
109  $password .= $char;
110  $i++;
111  }
112 
113  }
114 
115  // done!
116  return $password;
117  }
118 
125  function validatePassword($password)
126  {
127  if (dol_strlen($password) < $this->length) return 0;
128  return 1;
129  }
130 }
131 
Parent class for password rules/management modules.
conf($dolibarr_main_document_root)
Load conf file (file must exists)
Definition: inc.php:282
__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:105
getDescription()
Return description of module.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.