New: Ajout modules de gnration de mot de passe

This commit is contained in:
Laurent Destailleur 2006-03-12 13:15:29 +00:00
parent cb4cbdcc23
commit 52ccd92197
4 changed files with 153 additions and 15 deletions

View File

@ -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 '<table class="noborder" width=\"100%\">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td>';
print '<td>'.$langs->trans("Parameter").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
//print '<td>'.$langs->trans("Example").'</td>';
print "</tr>\n";
print '<form action="index.php" method="POST">';
// Choix du gestionnaire du générateur de mot de passe
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="constname" value="USER_PASSWORD_GENERATED">';
print '<input type="hidden" name="consttype" value="yesno">';
print '<tr '.$bc[$var].'><td>'.$langs->trans("GeneratePassword").'</td>';
print '<tr '.$bc[$var].'><td>'.$langs->trans("RuleForGeneratedPasswords").'</td>';
print '<td>';
$form->selectyesnonum('constvalue',USER_PASSWORD_GENERATED);
print "</td></tr>\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 "</td>";
//print "<td>".."</td>";
print "</tr>\n";
print '<tr><td colspan="2" align="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"></td></tr>';

View File

@ -0,0 +1,113 @@
<?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è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;
}
}
?>

View File

@ -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

View File

@ -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