phpDocumentor VFront
Authentication
[ class tree: VFront ] [ index: VFront ] [ all elements ]

Source for file auth.db_ext.php

Documentation is available at auth.db_ext.php

  1. <?php
  2. /**
  3.  * @package VFront
  4.  * @subpackage Authentication
  5.  * @author Mario Marcello Verona <marcelloverona@gmail.com>
  6.  * @copyright 2007 Mario Marcello Verona
  7.  * @version 0.90
  8.  * @license http://www.gnu.org/licenses/gpl.html GNU Public License
  9.  * @see auth
  10.  */
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.     /**
  18.      * Funzione di autenticazione mediante un database esterno, presente su un server remoto o locale
  19.      * Viene richiamata dalla classe {@link auth}
  20.      *
  21.      * @param string $user 
  22.      * @param string $passw 
  23.      * @see auth
  24.      * @return array 
  25.      */
  26.     function auth_db_ext($user$passw){
  27.         
  28.         global $conf_auth;
  29.     
  30.         
  31.         $sql_auth=sprintf("SELECT * FROM {$conf_auth['db_ext']['dbname']}.{$conf_auth['db_ext']['tabella']} 
  32.                            WHERE {$conf_auth['campo_email']}='%sAND {$conf_auth['campo_password']}='%s'",
  33.                         trim(addslashes($user)),
  34.                         personal_hash_db_ext(trim($passw))
  35.                         );
  36.         
  37.         if($conf_auth['db_ext']['dbtype']=='mysql'){
  38.             
  39.                             
  40.                 if(function_exists('mysqli_connect')){
  41.                     $link_tmp @mysqli_connect($conf_auth['db_ext']['host'],
  42.                                                $conf_auth['db_ext']['user'],
  43.                                                $conf_auth['db_ext']['passw'],
  44.                                                $conf_auth['db_ext']['dbname'],
  45.                                                $conf_auth['db_ext']['port']or die("Impossibile connettersi al server per l'autenticazione");
  46.                                                
  47.                                                
  48.                     $q_auth=mysqli_query($link_tmp,$sql_auth,MYSQLI_STORE_RESULT);
  49.         
  50.             
  51.                     if($q_auth!==false && mysqli_num_rows($q_auth)==1){
  52.                         
  53.                         $RS=mysqli_fetch_assoc($q_auth);
  54.                         
  55.                         
  56.                         return array('response'=>true,$RS);
  57.                     
  58.                     }
  59.                     else{
  60.                         
  61.                         return array('response'=>false);
  62.                     }
  63.                 }
  64.                 else die("Impossibile connettersi al server {$conf_auth['db_ext']['dbtype']} per l'autenticazioneestensione php mancante");
  65.         }    
  66.         else if($conf_auth['db_ext']['dbtype']=='postgres'){        
  67.                             
  68.                 if(function_exists('pg_connect')){
  69.                     $link_tmp @pg_connect("host={$conf_auth['db_ext']['host']} port={$conf_auth['db_ext']['port']} dbname={$conf_auth['db_ext']['dbname']} user={$conf_auth['db_ext']['user']} password={$conf_auth['db_ext']['passw']}")  or die("Impossibile connettersi al server per l'autenticazione");
  70.                     
  71.                     $q_auth=pg_query($link_tmp,$sql_auth);
  72.         
  73.         
  74.                     if(pg_num_rows($q_auth)==1){
  75.                         
  76.                         $RS=pg_fetch_assoc($q_auth);
  77.                         
  78.                         return array('response'=>true,$RS);
  79.                     
  80.                     }
  81.                     else{
  82.                         
  83.                         return array('response'=>false);
  84.                     }
  85.                 }
  86.                     else die("Impossibile connettersi al server {$conf_auth['db_ext']['dbtype']} per l'autenticazioneestensione php mancante");
  87.         }
  88.         
  89.         
  90.         else if($conf_auth['db_ext']['dbtype']=='odbc'){        
  91.                             
  92.                 if(function_exists('odbc_connect')){
  93.                     $link_tmp @odbc_connect($conf_auth['db_ext']['odbc_dsn'],$conf_auth['db_ext']['user'],$conf_auth['db_ext']['passw'])  or die("Impossibile connettersi al server per l'autenticazione");
  94.                     
  95.                     $q_auth=odbc_exec($link_tmp,$sql_auth);
  96.         
  97.         
  98.                         $RS=odbc_fetch_array($q_auth);
  99.         
  100.                         if(is_array($RS&& count($RS)>0){
  101.                             
  102.                             return array('response'=>true,$RS);
  103.                         }
  104.                         else{
  105.                             return array('response'=>false);
  106.                         }
  107.                 }
  108.                     else die("Impossibile connettersi al server {$conf_auth['db_ext']['dbtype']} per l'autenticazioneestensione php mancante");
  109.         }
  110.     
  111.     }
  112.     
  113.     /**
  114.      * Funzione di hash o crypt personalizzata, richiama il tipo di codifica impostata nel file CONF
  115.      * per le password in caso di autenticazione esterna tramite database
  116.      *
  117.      * @param string $passw 
  118.      * @return string 
  119.      */
  120.     function personal_hash_db_ext($passw){
  121.         
  122.         global $conf_auth;
  123.         
  124.         if($conf_auth['password_crypt']=='md5'){
  125.             
  126.             return md5($passw);
  127.         }
  128.         else if($conf_auth['password_crypt']=='sha1'){
  129.             
  130.             return sha1($passw);
  131.         }
  132.         
  133.         // ... altri metodi
  134.         
  135.         else{
  136.             
  137.             return $passw;
  138.         }
  139.     }
  140.  
  141. ?>

Documentation generated on Sat, 22 Sep 2007 11:49:48 +0200 by phpDocumentor 1.4.0a2