WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Simple and fast user authentication
Categories : PHP, PHP Classes, Authentication Click here to Update Your Picture
leaping langoor
Date : Apr 27th 2005
Grade : 3 of 5 (graded 4 times)
Viewed : 10675
File : No file for this code example.
Images : No Images for this code example.
Search : More code by leaping langoor
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

This is a simple and fast user authentication. Not adviced for commercial sites. Best for learning purposes. Check examples for usage.

<?php


/***************************************************************
** User authentication Class
** class Auth
**
** Author...: leapinglangoor [ leapinglangoor@yahoo.co.in ]
** Updated..: 21 Apr 2005
** Version..: v 1.2
**
***************************************************************/



class Auth
{
   
// Mysql Server details
    // Change the respective values here

   
var $db['host'] = 'localhost';     // Server Host name
   
var $db['database'] = 'login';    // Make sure the db exists first
   
var $db['user'] = 'root';        // Username for mysql
   
var $db['pass'] = '';            // Password for the user


/***************************************************************
** Function: connect();
**
** Description: Connect to the mysql server
**
** Usage: Only used inside this class. But can be used outside this class aswell
***************************************************************/


function connect()
{
   
mysql_connect( $this->db['host'], $this->db['user'], $this->db['pass'] );
   
mysql_select_db( $this->db['database'] );
}


/***************************************************************
** Function: install
**
** Description: Installs the table required for the login script
**
** Usage: Only used outside the class.
***************************************************************/

function install()
{
   
$this->connect();

   
mysql_query( "create table logins ( user char(32), pasword char( 32 ) )" );

   
mysql_close();
}

/***************************************************************
** Function: encrypt
**
** Description: Encrypt any username/Passwd
**
** Usage: Only used inside this class. But can be used outside this class aswell
***************************************************************/

function encrypt( $string )
{
   
$crypt = crypt( md5( $string ), md5( $string ) );
    return
$crypt;
}

/***************************************************************
** Function: Add_user
**
** Description: Add a user to the database
**
** Usage: Only used outside the class
***************************************************************/

function Add_user( $username, $password )
{
   
$this->connect();
   
$password = $this->encrypt( $password );
   
$username = $this->encrypt( $username );

   
$sql = "insert into logins values ('$username', '$password')";
   
mysql_query( $sql ) or die ('Can't create user');

    mysql_close();
}

/***************************************************************
** Function: Login
**
** Description: Check user authentcation and return if values exist in database
**
** Usage: Only used outside the classl
***************************************************************/

function Login( $user, $password )
{

    $auth = false;
    $user = $this->encrypt( $user );

    $this->connect();

    $sql = "select password from logins where user = '
$user'";
    $result = mysql_query( $sql ) or die( '
Cant login');;
    $pass = mysql_fetch_row($result);
    mysql_close();

    if ( $pass[0] == ( $this->encrypt( $password ) ) )
    {
        $auth = true;
    }

    return $auth;
}

} // End class login
?>


Examples on how to use:
Configure the variables in the class first!
Istallation example:

<?php
include( 'auth.php' );
$auth = new Auth; // Be careful, PHP is case sensitive it's Auth not auth
$auth->install();
?>


User creation:

<?php
include( 'auth.php' );
$auth = new Auth; // Be careful, PHP is case sensitive it's Auth not auth
$user = $somevar;
$pass = $someothervar;
$auth->Add_user( $user, $pass );
?>


Login script:

<?php
include( 'auth.php' );
$new = new Auth; // Be careful, PHP is case sensitive it's Auth not auth
$user = $somevar;
$pass = $someothervar;
if(
$auth->Login( $user, $pass ) )
{
    echo(
'Login Successful' );
}
else
{
    echo(
'Invalid Username/Password' );
}
?>



.htpasswd class
Categories : PHP, PHP Classes, Authentication
Use of bitmasks to represent permissions
Categories : PHP, Authentication, Bitwise Operators, Security, PHP Classes
Access_user Class - an easy to use system for protecting pages and register users.
Categories : PHP, Classes and Objects, Object Oriented, PHP Classes, Authentication
.htpassword manager for apache
Categories : PHP, PHP Classes, Authentication, Apache
PostGreSQL and MySQL 2 in 1 db Manager
Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL
Simple class to build tables with style sheets
Categories : HTML and PHP, PHP Classes, PHP
EAvalidator - This class can be used to validate an e-mail address by checking its domain.
Categories : PHP, PHP Classes, Email, Regexps
The Ajax Tree view class fetches data from a db for the requested parent category id. The data is then stored in an array and converted into JSON (Javascript Object Notation) format. This format is then used by JavaScript for populating tree view.
Categories : PHP, PHP Classes, Java Script, AJAX, Databases
PHP Object Example of the Perl DBI with MySQL
Categories : PHP, PHP Classes, MySQL, Databases, Perl
[PHP5] aDB PDO LIKE Database Abstraction. Switch easily from one db server to another, strong errors management, manage transactions, queries preparation and more.
Categories : PHP, PHP Classes, Databases, MS SQL Server, MySQL
Greatest Common Denominator - A simple class that finds the greatest common denominator for two integers.
Categories : PHP, PHP Classes, Math.
3 lines of Code to extract Tar, Zip, Gzip etc..
Categories : PHP, Filesystem, PHP Classes, Compression
HTML_Graphs uses PHP to provide a consistent interface for creating HTML based charts. The user of the class sets up arrays that are passed to html_graph() which then takes care of all the messy HTML layout.
Categories : Graphics, Arrays, PHP, PHP Classes, Charts and Graphs
Example of using the pcCalendar class, article 1468 on weberdev.com. Calendar example.
Categories : PHP, Date Time, PHP Classes, Calendar
Complete, simple working example of login screen and check on a unique page using php functions, cookies and mysql database.
Categories : PHP, Cookies, MySQL, HTML and PHP, Authentication