This commit is contained in:
Laurent Destailleur 2009-11-04 22:09:42 +00:00
parent 75d4627c8a
commit 93496b5902

View File

@ -18,34 +18,34 @@
*/ */
/** /**
\file htdocs/includes/login/functions_dolibarr.php * \file htdocs/includes/login/functions_dolibarr.php
\ingroup core * \ingroup core
\brief Authentication functions for Dolibarr mode * \brief Authentication functions for Dolibarr mode
\version $Id$ * \version $Id$
*/ */
/** /**
\brief Check user and password * \brief Check user and password
\param usertotest Login * \param usertotest Login
\param passwordtotest Password * \param passwordtotest Password
\return string Login if ok, '' if ko. * \return string Login if ok, '' if ko.
*/ */
function check_user_password_dolibarr($usertotest,$passwordtotest) function check_user_password_dolibarr($usertotest,$passwordtotest)
{ {
global $_POST,$db,$conf,$langs; global $_POST,$db,$conf,$langs;
dol_syslog("functions_dolibarr::check_user_password_dolibarr usertotest=".$usertotest); dol_syslog("functions_dolibarr::check_user_password_dolibarr usertotest=".$usertotest);
$login=''; $login='';
if (! empty($_POST["username"])) if (! empty($_POST["username"]))
{ {
// If test username/password asked, we define $test=false and $login var if ok, set $_SESSION["dol_loginmesg"] if ko // If test username/password asked, we define $test=false and $login var if ok, set $_SESSION["dol_loginmesg"] if ko
$table = MAIN_DB_PREFIX."user"; $table = MAIN_DB_PREFIX."user";
$usernamecol = 'login'; $usernamecol = 'login';
$entitycol = 'entity'; $entitycol = 'entity';
$sql ='SELECT pass, pass_crypted'; $sql ='SELECT pass, pass_crypted';
$sql.=' FROM '.$table; $sql.=' FROM '.$table;
$sql.=' WHERE '.$usernamecol." = '".addslashes($_POST["username"])."'"; $sql.=' WHERE '.$usernamecol." = '".addslashes($_POST["username"])."'";
@ -63,16 +63,16 @@ function check_user_password_dolibarr($usertotest,$passwordtotest)
$passtyped=$_POST["password"]; $passtyped=$_POST["password"];
$passok=false; $passok=false;
// Check crypted password // Check crypted password
$cryptType=''; $cryptType='';
if (! empty($conf->global->DATABASE_PWD_ENCRYPTED)) $cryptType=$conf->global->DATABASE_PWD_ENCRYPTED; if (! empty($conf->global->DATABASE_PWD_ENCRYPTED)) $cryptType=$conf->global->DATABASE_PWD_ENCRYPTED;
// By default, we used MD5 // By default, we used MD5
if (! in_array($cryptType,array('md5'))) $cryptType='md5'; if (! in_array($cryptType,array('md5'))) $cryptType='md5';
// Check crypted password according to crypt algorithm // Check crypted password according to crypt algorithm
if ($cryptType == 'md5') if ($cryptType == 'md5')
{ {
if (md5($passtyped) == $passcrypted) if (md5($passtyped) == $passcrypted)
{ {
$passok=true; $passok=true;
dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ok - ".$cryptType." of pass is ok"); dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ok - ".$cryptType." of pass is ok");
@ -82,14 +82,14 @@ function check_user_password_dolibarr($usertotest,$passwordtotest)
// For compatibility with old versions // For compatibility with old versions
if (! $passok) if (! $passok)
{ {
if ((! $passcrypted || $passtyped) if ((! $passcrypted || $passtyped)
&& ($passtyped == $passclear)) && ($passtyped == $passclear))
{ {
$passok=true; $passok=true;
dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ok - found pass in database"); dol_syslog("functions_dolibarr::check_user_password_dolibarr Authentification ok - found pass in database");
} }
} }
// Password ok ? // Password ok ?
if ($passok) if ($passok)
{ {