From 52ccd92197969bedd1672a59cef1fea54c8108cf Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 12 Mar 2006 13:15:29 +0000 Subject: [PATCH] =?UTF-8?q?New:=20Ajout=20modules=20de=20g=E9n=E9ration=20?= =?UTF-8?q?de=20mot=20de=20passe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/admin/security.php | 51 +++++--- .../generate/modGeneratePassDefault.class.php | 113 ++++++++++++++++++ htdocs/langs/en_US/admin.lang | 2 + htdocs/langs/fr_FR/admin.lang | 2 + 4 files changed, 153 insertions(+), 15 deletions(-) create mode 100644 htdocs/includes/modules/security/generate/modGeneratePassDefault.class.php diff --git a/htdocs/admin/security.php b/htdocs/admin/security.php index a96f494effe..185b6b71f85 100644 --- a/htdocs/admin/security.php +++ b/htdocs/admin/security.php @@ -39,19 +39,21 @@ if (!$user->admin) accessforbidden(); */ if ($_POST["action"] == 'update' || $_POST["action"] == 'add') { - if (! dolibarr_set_const($db, $_POST["constname"],$_POST["constvalue"],$typeconst[$_POST["consttype"]],0,isset($_POST["constnote"])?$_POST["constnote"]:'')) - { - dolibarr_print_error($db); - } - else - { - Header("Location: index.php"); - exit; - } + if (! dolibarr_set_const($db, $_POST["constname"],$_POST["constvalue"],$typeconst[$_POST["consttype"]],0,isset($_POST["constnote"])?$_POST["constnote"]:'')) + { + dolibarr_print_error($db); + } + else + { + Header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } } - +/* + * Affichage onglet + */ llxHeader(); @@ -77,19 +79,38 @@ $typeconst=array('yesno','texte','chaine'); print ''; print ''; -print ''; +print ''; +print ''; +//print ''; print "\n"; -print ''; + +// Choix du gestionnaire du générateur de mot de passe +print ''; print ''; print ''; print ''; -print ''; +print ''; print '\n"; + +$dir = "../includes/modules/security/generate"; +$handle=opendir($dir); +$arrayhandler=array('0'=>$langs->trans("DoNotSuggest")); +$i=1; +while (($file = readdir($handle))!==false) +{ + if (eregi('modGeneratePass([a-z]+).class.php',$file,$reg)) + { + $arrayhandler[strtolower($reg[1])]=$reg[1]; + $i++; + } +} +$form->select_array('constvalue',$arrayhandler,$conf->global->USER_PASSWORD_GENERATED); +print ""; +//print ""; +print "\n"; print ''; diff --git a/htdocs/includes/modules/security/generate/modGeneratePassDefault.class.php b/htdocs/includes/modules/security/generate/modGeneratePassDefault.class.php new file mode 100644 index 00000000000..b91524b2cb9 --- /dev/null +++ b/htdocs/includes/modules/security/generate/modGeneratePassDefault.class.php @@ -0,0 +1,113 @@ + + * + * 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ègle standard +*/ + +class modGeneratePassDefault +{ + var $id; + var $length; + + var $db; + var $conf; + var $lang; + var $user; + + + /** + * \brief Constructeur + * \param db Handler d'accès base + * \param conf Handler de conf + * \param lang Handler de langue + * \param user Handler du user connecté + */ + 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éré selon algorithme interne Dolibarr: 8 caractères, chiffres et caractères en minuscules mélangés"; + } + + /** + * \brief Renvoie exemple de mot de passe généré par cette règle + * \return string Exemple + */ + function getExample() + { + return $this->getNewGeneratedPassword(); + } + + /** + * \brief Génère le mot de passe + * \return string Renvoi mot de passe généré + */ + 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; + } + +} + +?> diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index ae25b070687..ddeaa6b5fd6 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -322,6 +322,8 @@ DelaysOfToleranceMembers=Tol ##### Users setup ##### UserGroupSetup=Users and groups module setup GeneratePassword=Suggest a generated password +RuleForGeneratedPasswords=Rule to generate suggested passwords +DoNotSuggest=Do not suggest any password ##### Company setup ##### CompanySetup=Companies module setup CustomerCodeChecker=Module for checking customer's code diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 1b7ec287ec4..b07ba63adc2 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -322,6 +322,8 @@ DelaysOfToleranceMembers=Tol ##### Users setup ##### UserGroupSetup=Configuration module utilisateurs et groupes GeneratePassword=Proposer un mot de passe généré +RuleForGeneratedPasswords=Règle pour la génération des mots de passes proposés +DoNotSuggest=Ne pas proposer ##### Company setup ##### CompanySetup=Configuration du module Sociétés CustomerCodeChecker=Module de contrôle des codes clients
'.$langs->trans("Parameter").''.$langs->trans("Value").''.$langs->trans("Parameter").''.$langs->trans("Value").''.$langs->trans("Example").'
'.$langs->trans("GeneratePassword").'
'.$langs->trans("RuleForGeneratedPasswords").''; -$form->selectyesnonum('constvalue',USER_PASSWORD_GENERATED); -print "
".."