Prev | Current Page 445 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

php");
CHAPTER 14 ?–  AUTHENTICATING YOUR USERS 379
// Designate authentication credentials, table name,
// username and password columns, password encryption type,
// and query parameters for retrieving other fields
$dblogin = array (
'dsn' => "mysql://corpweb:secret@localhost/corporate",
'table' => "logins",
'usernamecol' => "username",
'passwordcol' => "pswd",
'cryptType' => "md5"
'db_fields' => "*"
);
// Instantiate Auth_HTTP
$auth = new Auth_HTTP("DB", $dblogin) or die("Can't connect!");
// Begin the authentication process
$auth->start();
// Message to provide in case of authentication failure
$auth->setCancelText('Authentication credentials not accepted!');
// Check for credentials. If not available, prompt for them
if($auth->getAuth())
echo "Welcome, $auth->commonname
";
?>
Executing Listing 14-9, and passing along information matching that found in the
logins table, allows the user to pass into the restricted area. Otherwise, the error message
supplied in setCancelText() is displayed.
The comments should really be enough to guide you through the code, perhaps
with one exception regarding the $dblogin array. This array is passed into the Auth_HTTP
constructor along with a declaration of the data source type. See the Auth_HTTP documentation
at http://pear.php.net/package/Auth_HTTP for a list of the accepted data
source types. The array??™s first element, dsn, represents the Data Source Name (DSN).


Pages:
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457