<?php
/*
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()
*/
error_reporting(E_ALL);
include('userchecker.class.php');
//Get user data
$username = $_POST['username'];
$password = $_POST['password'];
//Set MySQL information
$serveraddr = '127.0.0.1';
$serveruser = 'root';
$serverpass = 'toor';
$serverdbname = 'users';
//Start session (not needed as the script will do it itself if no session is present)
session_start();
//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_table("users");
$user->set_fields('username', 'passwordhash');
//Start output
?>
<html>
<head>
<title>Simple login page</title>
</head>
<body>
<?php
if ($user->validate())
{
echo "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
}
?>
</body>
</html>
|