Miscellaneous

  Home arrow Miscellaneous arrow Page 2 - Writing a Basic Authentication System ...
MISCELLANEOUS

Writing a Basic Authentication System in PHP
By: bluephoenix
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 18
    2004-12-24

    Table of Contents:
  • Writing a Basic Authentication System in PHP
  • Storing Passwords
  • Getting the User Login
  • Processing the Login
  • Persisting the Authentication
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Writing a Basic Authentication System in PHP - Storing Passwords


    (Page 2 of 6 )

    Before we can begin coding with PHP, we need to first take a brief look at passwords. There are many different ways to manage and store a user's login ID and passwords, but one common method is to store them in a database.

    For security purposes, the passwords themselves should not be stored in the database in a plain text manner. Instead, the password can be processed by a one-way, irreversible encryption or hashing function and then the jumbled result is what is actually stored. That means the password supplied later will need to be encrypted/hashed before we compare it with the stored value. If they both match then we know the password is good.

    PHP's sha1 function should suffice for our purposes. It accepts a string and returns a 40 character hexadecimal hash representation. This hash cannot be converted back to the original string. The following is an example of sha1 in action:

    <?php
    $password 
    "secret";

    echo 
    $password;
    /* displays secret */

    $password sha1($password);

    echo 
    $password
    /* displays e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4 */
    ?>

    We'll assume for this tutorial that a database table named Users exists which stores the username and passwords hashed with the sha1 function.

    It's common mistake to not make the password column large enough to store the entire hash. Using sha1, the column should be 40 characters.

    More Miscellaneous Articles
    More By bluephoenix

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap