<?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;
}
|