PHP
  Home arrow PHP arrow Page 3 - Database and Password Security for Web Applications
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PHP

Database and Password Security for Web Applications
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2008-11-03


    Table of Contents:
  • Database and Password Security for Web Applications
  • The Password Management Script
  • The Code
  • Code continued

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Database and Password Security for Web Applications - The Code
    ( Page 3 of 4 )

    The script first checks to see if the form has been submitted:


    if(isset($_POST['key'])){


    If the form has been submitted, the form data is filtered. The process of filtering starts by checking to see if the submitted form data actually contains any values:


    //1. Check if form fields are filled in

    if(!filledin($_POST)){

    //print "Please enter your username and email.";

    $errmsg=”Please make sure that all required form fields are filled in”;

    $error=true;

    }


    Next, the type of data is tested. We expect only string values for the name and email values. So we check the data type by using the is_numeric() function of PHP. This function checks to see if the value that it is fed is a number:


    //check that the username and email address is string

    if( is_numeric($_POST['name']) && (is_numeric($_POST['email]))){

    //print "Please enter a valid username and email address.";

    $errmsg=" Please enter a valid username and email address.";

    $error=true;

    }


    We use regular expressions to test the format of the email address that the user entered into the form and set the appropriate error messages if the format is invalid:


    //Check if email address has correct format

    if(!eregi("^[a-z0-9]+[a-z0-9_-]*(.[a-z0-9_-]+)*@[a-z0-9_-]+(.[a-z0-9_-]+)*.(

    [a-z]+){2,}$", $_POST['email'])) {

    $errmsg=" Please enter a valid email address.";

    $error=true;

    }


    if no errors were found, the form values are transferred to shorter variables:


    if(!$error){

    $name=$_POST['name'];

    $em=$_POST['mail'];


    Then we check to see if the username that the user entered exists in the database. This is very important, because we will not be able to retrieve the database without this piece of information. Also, it is a good way to make sure that no unauthorized person gets the password:


    //2. Check if entered name exist


    $query="Select pw from users where uname='$name'" or die(mysql_error());

    $result= mysql_query($query);


    if(mysql_num_rows($result)>0){

    for ($i=0; $i<mysql_num_rows($result); $i++) {

    $row = mysql_fetch_assoc($result);



     
     
    >>> More PHP Articles          >>> More By David Web
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek