Jake,
Interesting response, but I'm not sure what your advice to me is?! 
Maybe it would help to see my code?
Here is my log_in.php...
PHP Code:
<?php //Build Date: 2012-02-04
// Initialize Session.
session_start();
// Initialize Variables.
$_SESSION['loggedIn'] = FALSE;
$salt = '';
// Access Constants.
require_once('../config/config.inc.php');
// *************************************************************
// HANDLE FORM. *
// *************************************************************
if ($_SERVER['REQUEST_METHOD']=='POST'){
// Form was Submitted (Post).
// Initialize Errors Array.
$errors = array();
// Trim all form data.
$trimmed = array_map('trim', $_POST);
// ************************
// Validate Form Data. *
// ************************
// Check Email.
if (empty($trimmed['email'])){
$errors['email'] = 'Please enter your E-mail address.';
}else{
$email = $trimmed['email'];
}
// Check Password.
if (empty($trimmed['pass'])){
$errors['pass'] = 'Please enter your Password.';
}else{
$pass = $trimmed['pass'];
}
// ********************************
// Check for Activation & Salt. *
// ********************************
if (empty($errors)){
// Form Complete.
// **********************
// Find Member Record. *
// **********************
// Connect to the database.
require_once(WEB_ROOT . 'private/mysqli_connect.php');
// Build query.
$q1 = 'SELECT activation_code, salt
FROM member
WHERE email=?';
// Prepare statement.
$stmt1 = mysqli_prepare($dbc, $q1);
// Bind variable to query.
mysqli_stmt_bind_param($stmt1, 's', $email);
// Execute query.
mysqli_stmt_execute($stmt1);
// Store results.
mysqli_stmt_store_result($stmt1);
// Check # of Records Returned.
if (mysqli_stmt_num_rows($stmt1)==1){
// Member Email found.
// Bind result-set to variables.
mysqli_stmt_bind_result($stmt1, $activationCode, $salt);
// Fetch record.
mysqli_stmt_fetch($stmt1);
// **********************
// Verify Activation. *
// **********************
if (is_null($activationCode)){
// Account Activated.
// ******************
// Check for Salt. *
// ******************
if (is_null($salt) || strlen($salt)==0){
// No Salt Found.
$errors['pass'] = 'A fatal error has occurred. Contact the System Admin';
}
}else{
// Account Not Activated.
$errors['pass'] = 'Please activate your Account before logging in.';
}// End of VERIFY ACTIVATION
// Close prepared statement.
mysqli_stmt_close($stmt1);
}// End of FIND MEMBER RECORD
}//End of CHECK FOR ACTIVATION & SALT
// ****************************
// Attempt to Log-In Member. *
// ****************************
if (empty($errors)){
// Valid Member Record.
// ************************
// Create Password Hash. *
// ************************
$hash = hash_hmac('sha512', $pass . $salt, VINEGAR);
// ************************
// Find Activated Member. *
// ************************
// Build query.
$q2 = 'SELECT id, first_name
FROM member
WHERE email=? AND hash=?';
// Prepare statement.
$stmt2 = mysqli_prepare($dbc, $q2);
// Bind variables to query.
mysqli_stmt_bind_param($stmt2, 'ss', $email, $hash);
// Execute query.
mysqli_stmt_execute($stmt2);
// Store results.
mysqli_stmt_store_result($stmt2);
// Check # of Records Returned.
if (mysqli_stmt_num_rows($stmt2)==1){
// Member was Found.
// Bind result-set to variables.
mysqli_stmt_bind_result($stmt2, $memberID, $memberFirstName);
// Fetch record.
mysqli_stmt_fetch($stmt2);
// Set Session variables.
$_SESSION['memberID'] = $memberID;
$_SESSION['memberFirstName'] = $memberFirstName;
$_SESSION['loggedIn'] = TRUE;
// Close prepared statement.
mysqli_stmt_close($stmt2);
// Close the connection.
mysqli_close($dbc);
// ********************
// Redirect Member. *
// ********************
// Add-a-Comment Redirect.
if (isset($_GET['addComment']) && ($_GET['addComment']==TRUE)){
header("Location: " . BASE_URL . "articles/add_comment.php");
// End script.
exit();
}
// Normal Redirect.
if (isset($_SESSION['returnToPage'])){
header("Location: " . BASE_URL . $_SESSION['returnToPage']);
}else{
// Take user to Home Page.
header("Location: " . BASE_URL . "index.php");
}
}else{
// Member Not Found.
$_SESSION['loggedIn'] = FALSE;
$errors['pass'] = 'The E-mail and Password do not match those on file.';
}// End of FIND ACTIVATED MEMBER
}else{
// Invalid Member Record.
// Drop through to display Form.
}//End of ATTEMPT TO LOG-IN MEMBER
}else{
// Form was not Submitted (Get).
// Drop through to display Form.
}//End of HANDLE FORM
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- ################## DEBBIE ##################### -->
<!-- HTML Metadata -->
<title>Member Log-In</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<!-- Page Stylesheets -->
<link type="text/css" rel="stylesheet" href="/css/_main.css" />
<link type="text/css" rel="stylesheet" href="/css/_layout.css" />
<link type="text/css" rel="stylesheet" href="/css/top_menu.css" />
<link type="text/css" rel="stylesheet" href="/css/components.css" />
</head>
<body>
<div id="pageWrapper" class="clearfix">
<div id="pageInner">
<!-- BODY HEADER -->
<?php require_once(WEB_ROOT . 'components/body_header.inc.php'); ?>
<!-- MIDDLE COLUMN -->
<div id="pageMidCol_1">
<!-- LOG-IN FORM -->
<form id="login" action="" method="post">
<fieldset>
<legend>Log-In</legend>
<ul>
<!-- Cookies Note -->
<li id="acceptCookies"><b>*</b>Your browser must accept cookies in order to log in.</li>
<!-- Article Heading -->
<?php
if (isset($_GET['addComment']) && ($_GET['addComment']==TRUE)){
// Trying to Add Comment.
if (isset($_SESSION['heading'])){
// Article Heading exists.
echo '<li>
Please log-in to comment on the article:<br />
<span id="articleHeading">"' . $_SESSION['heading'] . '"</span>
</li>';
}
}//End of CHECK FOR ARTICLE HEADING
?>
<!-- Email -->
<li>
<label for="email">E-mail:</label>
<input id="email" name="email" type="text" maxlength="60" />
<?php
if (!empty($errors['email'])){
echo '<span class="error">' . $errors['email'] . '</span>';
}
?>
</li>
<!-- Password -->
<li>
<label for="pass">Password:</label>
<input id="pass" name="pass" type="password" maxlength="40" />
<?php
if (!empty($errors['pass'])){
echo '<span class="error">' . $errors['pass'] . '</span>';
}
?>
</li>
<!-- Submit Form -->
<li>
<input type="submit" name="logIn" class="button" value="Log In" />
</li>
</ul>
</fieldset>
</form>
</div><!-- End of #MIDDLE -->
</div><!-- End of #INNER -->
</div><!-- End of #WRAPPER -->
<!-- BODY FOOTER -->
<?php require_once(WEB_ROOT . 'components/body_footer.inc.php'); ?>
</body>
</html>
In the next couple of days I hope to have a working demo of my entire website up on the Internet so people trying to help me out can actually see what a user would see.
I think the code above is pretty "tight", but it can be pretty intense reading it with all of its moving parts and branches.
Sometimes it seems like it would be better if it was broken up into 5-6 pieces.
Conceptually what I am doing in my code is this...
1.) Verify Form was completed
2.) Verify Member Account was Activated
3.) Verify Member Record has a Salt
4.) Create Hash based on Form Inputs and Salt
5.) Attempt to Log In Member (i.e. Find Member Record)
6.) Redirect Member
Debbie
Bookmarks