Login   Register  
PHP Classes
elePHPant
Icontem

File: customclass.http.auth.eg.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  >  customclass.http.auth.eg.php  >  Download  
File: customclass.http.auth.eg.php
Role: Example script
Content type: text/plain
Description: Example: Authentication by Custom Class
Class: Basic Realm Authentication Controller
Authenticate users with HTTP basic mechanism
Author: By
Last change: fix session hijacking & fixation
Date: 2013-01-08 20:30
Size: 1,350 bytes
 

Contents

Class file image Download
<?php

class myWebsiteUsers{

    var 
$users;
    function 
fixUser(){
        
$this->users['demo']='demo';
        
$this->users['admin']='admin1';
        
$this->users['user']='admin2';
        
$this->users['client']='admin3';
    }
    function 
fixUserSecure(){
        
$this->users['demo']=$this->encrypt('demo');
        
$this->users['admin']=$this->encrypt('admin1');
        
$this->users['user']=$this->encrypt('admin2');
        
$this->users['client']=$this->encrypt('admin3');
    }

    function 
encrypt($p_subject){ return md5($p_subject); }
    private function 
isUserOKX($p_user$p_pass$p_secure=false){
        
$this->fixUser();
        if(
$p_secure$this->fixUserSecure();
        if(isset(
$this->users[$p_user]) && $this->users[$p_user]==$p_pass) return true;
    }
    function 
isUserOK($p_user$p_pass){ return $this->isUserOKX($p_user$p_pass); }
    function 
isUserOKSecured($p_user$p_pass){ return $this->isUserOKX($p_user$p_passtrue); }

}



session_start();
include_once 
'http.auth.cls.php';
$user=new myWebsiteUsers();
#$httpauth=new HTTPBasicRealmAuth('authentication by custom class', $user, 'isUserOK');
$httpauth=new HTTPBasicRealmAuth('authentication by custom class'$user'isUserOKSecured'truefalse);
$httpauth->setPasswordEncryptMethod(array($user'encrypt'));
$httpauth->setEncryptedPasswordFlag(true);
$httpauth->check();


include 
'secure.file.eg.php';