PHP
  Home arrow PHP arrow Page 2 - Filters and Login Systems for Web Application Security
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

Filters and Login Systems for Web Application Security
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2008-10-06


    Table of Contents:
  • Filters and Login Systems for Web Application Security
  • Definition and Storage File
  • The Login page
  • The code

  • 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


    Filters and Login Systems for Web Application Security - Definition and Storage File
    ( Page 2 of 4 )

    The file that defines and stores the functions has the following content:


    <?

    function userexist($username){

    include('../config.inc');

    $result=mysql_query("Select uname from users where uname='$username'") or die(mysql_error());

    if(mysql_num_rows($result)>0)

     

    return true;//username exist

    else

    return false;//username not in db

    }

    The first function, called userexist, is responsible for finding out whether a particular username already exists in the database. This function is used when a new user registers for our site or during the authentication process. The function takes only one argument. It returns a value of true or false.

    function sendpass($user){

    include("../config.inc");

    $result =mysql_query("select pw from users where uname='$user'") or die(mysql_error());

    if(mysql_num_rows($result)>0)

    return true;//password exist

    else

    return false;//password not in db

    }

    The sendpass()function is used to determine whether the user password exists or matches a password that is stored in the database. The function takes only one argument. It returns a value of true or false.

    function filledin($form_vars){

    foreach($form_vars as $key=> $value)

    {

    if(!isset($key) || ($value == ''))

    return false;

    }

    return true;

    }

    This is a handy function that checks to see if all the form variables have a value when submitted. It basically loops through all the form values and returns false if it is empty and true if it is not.

    function changepw($name){

    $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'];

    echo '

    <center><form name="form1" method="post" action="forgotten.php">';

    echo 'Please fill in the following:<br>';

     

    echo ' <table width="445" border="0">';

    echo ' <tr>

    <td width="187"><div align="left">Old Password</div></td>

    <td width="242"><input name="oldpass" type="text" size="40" value="'.$pass.'"></td>

    </tr>

    <tr>

    <td><div align="left">New Password </div></td>

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

    </tr>';

     

    echo '</table>';

    echo '<br>

    <input name="submit" type="submit" value="Save">';

    echo '</form>';


    }

    }

    }

    The changepw() function is responsible for enabling a user to change his or her password. The function presents the user with a form that takes two passwords, the old one and the new one. The new password is then submitted to a script called forgotten and processed there.

    function update($newpass,$uname){

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

    //1. Check fields are filled in

    if (!filledin($form_vars)){

    echo "Please ensure that you have filled in ALL fields.";

    exit;

    }else{

    $newpass=$_POST['newpass'];



    }


    include "config.inc";

    $query="Update users SET pw='$newpass' Where uname=$uname Limit 1 ";

    $result=mysql_query($query);

    if(mysql_affected_rows()==1){

    echo "Record number <b>$id</b> has been updated";

    }else{

    echo "Could not update record number <b>$id</b> because " .mysql_error() . "";

    }

    }

    }

    ?>

    The update function does exactly what the name suggests. It updates the user details. This function is used together with an HTML form that presents the user with her login details, such as name, surname and password etc. The user then changes the details to what they want and then submits the form.



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