PHP Classes

File: validate.php

Recommend this page to a friend!
  Classes of giuseppe lucarelli   reconfig   validate.php   Download  
File: validate.php
Role: Auxiliary script
Content type: text/plain
Description: user authentication script
Class: reconfig
Get configuration from files, pages and databases
Author: By
Last change: removed 'notice' problem
Date: 9 years ago
Size: 1,093 bytes
 

Contents

Class file image Download
<?php
/* Example:
    $REC = new REConfig();
    $REC->auth_type='httpHeader';
    //$REC->auth_passwd='.htpasswd'; // only if necessary
    //$REC->auth_host='somehost'; // only if necessary
    $REC->auth_script = 'validate.php';
    $REC->auth_func = 'ValidateAccess';
    $REC->auth_user = $_POST['auth_user'];
    $REC->auth_pass = $_POST['auth_pass'];
    $REC->Init($HTML['building'],'building');
*/

define('__PASSWD','.htpasswd');

/* download at http://www.openwall.com/phpass/ */
if(!class_exists('PasswordHash')) {
    require_once(
'PasswordHash.php');
}

function
ValidateUser($auth_user,$auth_pass,$auth_passwd=null,$auth_host=null) {
    if(!
$fp = fopen(($auth_passwd !== null ? $auth_passwd : __PASSWD),'r+')) return false;
   
rewind($fp);
    while(!
feof($fp) && trim($user = array_shift(@explode(":",$line = rtrim(fgets($fp)))))) {
        if(
$user == $auth_user) {
            list(
$user,$pass)=explode(':',$line);
           
$t_hasher = new PasswordHash(8, FALSE);
            return
$t_hasher->CheckPassword($auth_pass,$pass);
        }
    }
    return
false;
}