PHP Classes

File: userchecker.example.php

Recommend this page to a friend!
  Classes of Jon Gjengset   User Checker   userchecker.example.php   Download  
File: userchecker.example.php
Role: Example script
Content type: text/plain
Description: Simple example of usage
Class: User Checker
Authenticate users with records in a MySQL table
Author: By
Last change: Proper revision
Date: 17 years ago
Size: 1,552 bytes


Class file image Download
Available functions:
    function __construct($user, $pass, $passcheck = 'md5', $session = FALSE)
    function set_db_connection($serveraddr, $serveruser, $serverpass, $serverdbname)
    function set_table($dbtable)
    function set_fields($userfield, $passfield)
    function validate()
    function print_query()
    function get_user_info()

//Get user data
$username = $_POST['username'];
$password = $_POST['password'];

//Set MySQL information
$serveraddr = '';
$serveruser = 'root';
$serverpass = 'toor';
$serverdbname = 'users';

//Start session (not needed as the script will do it itself if no session is present)

//Username and password can be passed directly as the class takes care of injection attempts
//Remember to set the connection information using set_db_connection()!
$user = new User($username, $password, 'md5');
$user->set_db_connection($serveraddr, $serveruser, $serverpass, $serverdbname);
$user->set_fields('username', 'passwordhash');

//Start output
<title>Simple login page</title>

if ($user->validate())
"Congratulations, your credentials have been accepted!";
else if (
$user->validate() < 1 || empty($username) || empty($password))
?><form action="" method="post"><input type="text" name="username" /><input type="password" name="password" /><input type="submit" value="Login" /></form><?php