Ejemplo n.º 1
0
<?php

require_once "Auth/HTTP.php";
// Designate authentication credentials, table name,
// username and password columns, password encryption type,
// and query parameters for retrieving other fields
$dblogin = array('dsn' => "mysqli://*****:*****@localhost/chapter14", 'table' => "logins", 'usernamecol' => "username", 'passwordcol' => "pswd", 'cryptType' => "md5", 'db_fields' => "*");
// Instantiate Auth_HTTP
$auth = new Auth_HTTP("MDB2", $dblogin) or die("Can't connect!");
// Message to provide in case of authentication failure
$auth->setCancelText('Authentication credentials not accepted!');
// Begin the authentication process
$auth->start();
// Check for credentials. If not available, prompt for them
if ($auth->getAuth()) {
    echo "Welcome, {$auth->getAuthData('username')}<br />";
}
?>

Ejemplo n.º 2
0
<?php

require_once 'config.php';
require_once 'db_login.php';
require_once 'Auth/HTTP.php';
// We use the same connection string as the pear DB functions
$AuthOptions = array('dsn' => "mysql://{$db_username}:{$db_password}@{$db_host}/{$db_database}", 'table' => "users", 'usernamecol' => "username", 'passwordcol' => "password", 'cryptType' => "md5", 'db_fields' => "*");
//echo "<br/>mysql://$db_username:$db_password@$db_host/$db_database\n<br/>";
$authenticate = new Auth_HTTP("DB", $AuthOptions);
$authenticate->setRealm('Member Area');
$authenticate->setCancelText('<h2>Access Denied</h2>');
// request authentication
$authenticate->start();
// compare username and password to stored values
if ($authenticate->getAuth()) {
    if (!isset($_SESSION)) {
        session_start();
    }
    $smarty->assign('blog_title', $blog_title);
    $smarty->display('header.tpl');
    //setup session variable
    $_SESSION['username'] = $authenticate->username;
    $_SESSION['first_name'] = $authenticate->getAuthData('first_name');
    $_SESSION['last_name'] = $authenticate->getAuthData('last_name');
    $_SESSION['user_id'] = $authenticate->getAuthData('user_id');
    echo $_SESSION['username'];
    echo $_SESSION['first_name'];
    echo $_SESSION['last_name'];
    echo $_SESSION['user_id'];
    echo "Login successful. Great to see you ";
    echo $authenticate->getAuthData('first_name');
Ejemplo n.º 3
0
<?php

require_once "mysql.php";
require_once "Auth/HTTP.php";
// setting the database connection options
$AuthOptions = array('dsn' => "mysql://{$sql_user}:{$sql_pass}@{$sql_host}/{$sql_data}", 'table' => "auth", 'usernamecol' => "username", 'passwordcol' => "password", 'cryptType' => "none", 'db_fields' => "*");
$auth_http = new Auth_HTTP("DB", $AuthOptions);
$auth_http->setRealm('admin4am');
// realm name
$auth_http->setCancelText('<h2>Error 401 - no login!</h2>');
// error message if authentication fails
$auth_http->start();
// starting the authentication process