PHP
  Home arrow PHP arrow Page 4 - 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 - Code continued
    ( Page 4 of 4 )

    Once the password is successfully retrieved, we build the email message that we want to send to the user. Because we are going to use PHP’s mail() function, we need to define to whom the message is going, the subject of the email message, from whom it is coming and the body of the mail message:


    $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";

    }


    We also deal with what happens when the SQL query fails to match the given username to a name in the database:


    }else{

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

    exit;

    }


    If everything has gone well and no errors were encountered, we send the message containing the password to the given email address:

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

    }

    }

    }

    ?>


    The user enters the information that is used by the script in an HTML form. The form itself is contained in a table and has the following code:


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


    The first element takes the username:


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

    </tr>

    <tr>

    The second element takes the email address:

    <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">

    And finally, the hidden element with the name value of “key” is also present:

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

    </tr>

    <tr>

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

    <td></td>

    </tr>

    </table>


    In the next article we will look at some of the most common attacks on databases.



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