PHP
  Home arrow PHP arrow Page 2 - 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 Password Management Script
    ( Page 2 of 4 )

    The password management script is responsible for retrieving and sending a password to a user. This happens when a registered user forgets his or her password and needs to be reminded of what the password was. The logic of the script is very simple; it presents the user with a form that takes the username and email address. It then checks to see if the user exists in the database. If the user does exist, it retrieves the password of the user and sends it to the user using the PHP mail() function.


    <?


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


    $errmsg=””;

    $error=false;


    //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;

    }


    //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;

    }



    //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(!$error){

    $name=$_POST['name'];

    $em=$_POST['mail'];


    //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);


    $pass=$row['pw'];

    $to="$emrn";

    $from="From: admin@mysite.comrn";

    $msg="Password:$passrn";

    $msg .="Username:$namern";

    $msg .="Please change your password as soon as you logonrn";

    $subject="From Admin re:Your Login Passwordrn";

    }

    }else{

    print "Your username is either spelled incorrect or does not exist, please try again";

    exit;

    }



    //4. Send password to user

    if(mail($to,$subject,$msg,$from)){

    print "Your password has been sent to <b>$em</b>" ;

    }else{

    print "could not send email";

    }

    }

    }

    ?>



    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/primary/Templates/was.dwt.php" codeOutsideHTMLIsLocked="false" -->

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <!-- InstanceBeginEditable name="doctitle" -->

    <title>WebSecure::Password</title>

    <!-- InstanceEndEditable -->

    <!-- InstanceBeginEditable name="head" -->

    <!-- InstanceEndEditable -->

    <link href="Templates/was.css" rel="stylesheet" type="text/css" />

    </head>


    <body>

    <table width="99%" border="1">

    <tr>

    <td bgcolor="#333333" class="header">Web Secure</td>

    </tr>

     

     

    <tr>

    <td><!-- InstanceBeginEditable name="main" -->

    <form name="form1" method="post" action="../forgotten.php">

    Please fill in the following:

    <br>

    <table width="445" border="0">

    <tr>

    <td width="187"><div align="left">Username</div></td>

    <td width="242"><input name="name" type="text" size="40"></td>

    </tr>

    <tr>

    <td><div align="left">Email <font color="#FF0000" size="2">(password will be sent to this email address)</font> </div> </td>

    <td><input name="mail" type="text" size="40">

    <input type="hidden" name="key" /></td>

    </tr>

    <tr>

    <td> <input name="submit" type="submit"> </td>

    <td></td>

    </tr>

    </table>


    </form>

     

     

    <!-- InstanceEndEditable --></td>

    </tr>

    <tr>

    <td class="copy">&copy;2008</td>

    </tr>

    </table>

    </body>

    <!-- InstanceEnd --></html>



     
     
    >>> 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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek