mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
114 lines
2.7 KiB
PHP
114 lines
2.7 KiB
PHP
|
|
<?php
|
|||
|
|
/* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
|||
|
|
*
|
|||
|
|
* This program is free software; you can redistribute it and/or modify
|
|||
|
|
* it under the terms of the GNU General Public License as published by
|
|||
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|||
|
|
* (at your option) any later version.
|
|||
|
|
*
|
|||
|
|
* This program is distributed in the hope that it will be useful,
|
|||
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|||
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|||
|
|
* GNU General Public License for more details.
|
|||
|
|
*
|
|||
|
|
* You should have received a copy of the GNU General Public License
|
|||
|
|
* along with this program; if not, write to the Free Software
|
|||
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
|
* or see http://www.gnu.org/
|
|||
|
|
*
|
|||
|
|
* $Id$
|
|||
|
|
* $Source$
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
\file htdocs/includes/modules/security/generate/modGeneratePassDefault.class.php
|
|||
|
|
\ingroup core
|
|||
|
|
\brief Fichier de gestion de la generation de mot de passe selon r<EFBFBD>gle standard
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
class modGeneratePassDefault
|
|||
|
|
{
|
|||
|
|
var $id;
|
|||
|
|
var $length;
|
|||
|
|
|
|||
|
|
var $db;
|
|||
|
|
var $conf;
|
|||
|
|
var $lang;
|
|||
|
|
var $user;
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* \brief Constructeur
|
|||
|
|
* \param db Handler d'acc<EFBFBD>s base
|
|||
|
|
* \param conf Handler de conf
|
|||
|
|
* \param lang Handler de langue
|
|||
|
|
* \param user Handler du user connect<EFBFBD>
|
|||
|
|
*/
|
|||
|
|
function modGeneratePassDefault($db, $conf, $langs, $user)
|
|||
|
|
{
|
|||
|
|
$this->id = "default";
|
|||
|
|
$this->length = 8;
|
|||
|
|
|
|||
|
|
$this->db=$db;
|
|||
|
|
$this->conf=$conf;
|
|||
|
|
$this->langs=$langs;
|
|||
|
|
$this->user=$user;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* \brief Renvoi la description du module
|
|||
|
|
* \return string Texte descripif
|
|||
|
|
*/
|
|||
|
|
function getDescription()
|
|||
|
|
{
|
|||
|
|
return "Renvoie un mot de passe g<>n<EFBFBD>r<EFBFBD> selon algorithme interne Dolibarr: 8 caract<63>res, chiffres et caract<63>res en minuscules m<>lang<6E>s";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* \brief Renvoie exemple de mot de passe g<EFBFBD>n<EFBFBD>r<EFBFBD> par cette r<EFBFBD>gle
|
|||
|
|
* \return string Exemple
|
|||
|
|
*/
|
|||
|
|
function getExample()
|
|||
|
|
{
|
|||
|
|
return $this->getNewGeneratedPassword();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* \brief G<EFBFBD>n<EFBFBD>re le mot de passe
|
|||
|
|
* \return string Renvoi mot de passe g<EFBFBD>n<EFBFBD>r<EFBFBD>
|
|||
|
|
*/
|
|||
|
|
function getNewGeneratedPassword()
|
|||
|
|
{
|
|||
|
|
// start with a blank password
|
|||
|
|
$password = "";
|
|||
|
|
|
|||
|
|
// define possible characters
|
|||
|
|
$possible = "0123456789bcdfghjkmnpqrstvwxyz";
|
|||
|
|
|
|||
|
|
// set up a counter
|
|||
|
|
$i = 0;
|
|||
|
|
|
|||
|
|
// add random characters to $password until $length is reached
|
|||
|
|
while ($i < $this->length)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
// pick a random character from the possible ones
|
|||
|
|
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
|
|||
|
|
|
|||
|
|
// we don't want this character if it's already in the password
|
|||
|
|
if (!strstr($password, $char))
|
|||
|
|
{
|
|||
|
|
$password .= $char;
|
|||
|
|
$i++;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// done!
|
|||
|
|
return $password;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
?>
|