PHP
  Home arrow PHP arrow Page 2 - Using the PHP Crypt Function
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Using the PHP Crypt Function
By: Chris Root
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 32
    2005-01-17

    Table of Contents:
  • Using the PHP Crypt Function
  • A Practical Example
  • Login
  • A Few Words About Storage and Security

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using the PHP Crypt Function - A Practical Example


    (Page 2 of 4 )

    First let's set up a form for entering a username and password to add a new user into the system. Let's use an example of a form for an admin interface to administer a Company X product database for Web display.

    <html>
    <head>
    <title>Company X Products Admin Application Add New User </title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <h1>Administration Interface login: Add new User</h1>
    <form name="form1" method="post" action="admin_login_newuserbe.php">
    <p>
    <input name="uname" type="text" id="uname" size="8" maxlength="8">
       <strong>Enter User Name</strong>
    <br>
    <input name="pword" type="password" id="pword" size="8" maxlength="8">
       <strong>Enter Password</strong>
       <br><input type="submit" name="Submit" value="Add">
    </p>
    </form>
    </body>
    </html>

    When the form is submitted to "admin_login_newuserbe.php" the crypt function is used to encrypt the new username. We first confirm that both fields have entries:

    if(empty($_POST[pword]) || empty($_POST[uname]))
    {
       echo "<html><head></head>
       <body><h1>You must enter both a username and password.
       <a href = \"admin_login_newuser.html\">Try Again?
       </a></h1></body></html>";
    }

    Additional validation could be added to this either on the client side (using Javascript) or on the server side as needed. Next we will use crypt to encrypt our password and neatly trim leading and trailing white space from our username. They can then be stored in a database or flat file.

    else
    {
       $pwrd = crypt(trim("$_POST[pword]"));
       $user = trim("$_POST[uname]");
    //Code for accessing you database or flat file goes here.

    More PHP Articles
    More By Chris Root


       · However, md5() in not encryption, its hashing; just though I would point that...
       · Yes actually you are correct. Not a lot of people know the difference but it is an...
       · Using a non standard hashing (or crypto) function is a good way to get in troubles...
       · Actually Crypt is entirely based on standards. It uses standard ciphers available...
       · First thing that came to my mind is implementing this function with passwords. Since...
       · The way I would manage this is for a non encrypted version to be stored in a...
       · can you explain hashing? new to this, and thought md5 was encrypting the password? ...
       · Can anyone tell the difference between hashing and crypting?and which one is...
       · The best explanation I have seen for the difference is...
       · This is the way it SHOULD be. When a user loses his password, he gets sent a new...
       · With appreciation to the author, there are serious weaknesses here. 1) Crypt()...
       · Has nobody spotted the obvious flaw here? You are still sending the password in...
     

       

    PHP ARTICLES

    - Using Aliases and the Autoload Function with...
    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Sub Classing Exceptions in PHP 5
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT