Home arrow PHP arrow Page 4 - User Authentication for a Project Management Application

Checking the User and Email - PHP

In the last article, we discussed in detail the user creation script. We looked at what information the script gets from the form and how it "cleans" and verifies form values, and then looked at how the user is informed about his or her log-in credentials. In this article, the conclusion to our four-part series, we'll finish the discussion.

TABLE OF CONTENTS:
  1. User Authentication for a Project Management Application
  2. User Information
  3. The Script
  4. Checking the User and Email
By: David Web
Rating: starstarstarstarstar / 1
August 18, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

After running the initial checks on the form values, the code gets to the most important bit of the program, which is to see if the user and email address actually exists in the database. Remember, anyone can enter any email address with the correct username and try to get the password sent to an email address that is not connected to the username. Therefore, in this program, we will guard against this tactic by checking (in the database) to see if the username and email address entered are connected:

if(!$err){

$cleanuname = mysql_escape_string($_POST['uname']);

$cleanemail = mysql_escape_string($_POST['email']);

$unamecheck = "SELECT email,name,sname FROM users WHERE username='".$cleanuname."' and email = '".$cleanemail."'";

$result=mysql_query($unamecheck);

$num=mysql_num_rows($result);

if($num > 0){

$row = mysql_fetch_assoc($result);

$thepass = $row['upass'];

$theName = $row['name'];

Once we’ve established that the password actually belongs to the person requesting it, we then proceed to create a email message, and send the password to the email address provided.

//build email headers

//this text will appear in the subject line of the email

$subject = "Project Management - Password Recovery";

//this is the recipient of the email

$to = $cleanemail;

//sender name

$from_name = "Project Management Application";

//sender address

$from_email = "website@mywebsite.com";

$headers = "From: " . $from_name . " <" . $from_email . ">";

//build message

$msg = "<html>

<head>

<title>Project Management</title>

<link rel='stylesheet' type='text/css' href='http://www.yourwebsitelocationhere.com/loginstyle.css'>

</head>

<body>

<table width='100%' border='0' cellspacing='0' cellpadding='0'>

<tr>

<td><p>Dear <b>".$theName."</b></p>

Below is the password you requested:<br />

<br />

<b>Password:</b> ".$thepass.";


</td>

</tr>

</table>";

$msg .= "</body>

</html>";


mail($to, $subject, $msg, $headers);

}else{

If the information that the user provides does not match up, we set the appropriate error message and display it in the password form.

$err=true;

$errmsg .="The information you entered is incorrect or does not exists. ";


}

}

}//end submit

Like the other forms, the password form allows a space on the form to display the error message. 

<?php if(isset($errmsg)){?>

<tr>

<td colspan="2" class="errmsg"><?php echo $errmsg; ?></td>

</tr>

<tr>

<td colspan="2">&nbsp;</td>

</tr>

<tr>

<?php

}

?>

Conclusion

That is all there is to the user authentication system for the project management application. I am sure there are some things that can be improved, and no doubt some of you will do so. We’ve covered a lot of ground in the last couple of articles dealing with user authentication and I hope that it will give some of you more ideas on how to make your login scripts more secure.



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: