Login   Register  
PHP Classes
elePHPant
Icontem

File: db.basic.realm.auth.cls.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Md. Shahadat Hossain Khan Razon  >  Basic Realm Authentication Controller  >  db.basic.realm.auth.cls.php  >  Download  
File: db.basic.realm.auth.cls.php
Role: Example script
Content type: text/plain
Description: Example: Authentication by Existing Database User
Class: Basic Realm Authentication Controller
Authenticate users with HTTP basic mechanism
Author: By
Last change: fix session hijacking & fixation
Date: 1 year ago
Size: 1,281 bytes
 

Contents

Class file image Download
<?php

/* basic realm auth by database */

/**
 * the sql.cls.php found from
 * http://www.phpclasses.org/package/3406-PHP-Execute-common-MySQL-database-SQL-queries.html
 * http://www.phpclasses.org/package/3406/
 */
include_once 'sql.cls.php';
class 
httpBasicAuthThroughDB extends sqlFunctions{

    public function 
isUserAuthorized($p_user$p_pass){
        
$usr=$this->getRowsValX('select * from `users` where `user_id`=\''.self::sqlSafeString($p_user).'\' and `password`=md5(\''.self::sqlSafeString($p_pass).'\') order by `user_id` limit 1');
        return (!
is_bool($usr) && is_array($usr));
    }

    public function 
isUserAuthorizedSecure($p_user$p_pass){
        
$usr=$this->getRowsValX('select * from `emp` where `id`=\''.self::sqlSafeString($p_user).'\' and `pass`=\''.self::sqlSafeString($p_pass).'\' order by `id` limit 1');
        return (!
is_bool($usr) && is_array($usr));
    }

}

session_start();
include_once 
'http.auth.cls.php';
$db=new httpBasicAuthThroughDB();
$db->openMyDatabaseX('localhost''root''your password''your database');
#$httpauth=new HTTPBasicRealmAuth('authentication by database', $db, 'isUserAuthorized');
$httpauth=new HTTPBasicRealmAuth('authentication by database'$db'isUserAuthorizedSecure'true);

include 
'secure.file.eg.php';