Okay so I have this page which is supposed to allow a user to login with their password which is encrypted in the database with AES. I want to pull the encrypted password out of the DB, decrypt it and compare it to the password the user enters. Here's my code:
<?php
session_start();
$validUser = false;
// see if they want to logout from a current session
$tOption = $_GET['cmd'];
if($tOption=="logout") {
unset($_SESSION['SAFEUSER']);
}
?>
<html>
<body>
<?php
// are they attempting to log into the menu?
// alternative syntax that uses the submit button's value
// if( $_POST['Fsubmit'] == "lookupnow" ) {
if( ($_POST['Femail'] > "") or ($_POST['Fpassword'] > "") ) {
// look 'em up in the database to validate credentials
// establish values for DB credentials
$hostname = 'localhost';
$dbname = '';
$username = '';
$userpass = '';
$passkey = "sgjbasjgbaslhflshfoashf";
// get connected to the DB
try {
$DBH = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $userpass);
}
catch(PDOException $e) {
echo $e->getMessage();
}
$tEmail = $_POST['Femail'];
$tPassword = $_POST['Fpassword'];
/*$secureSQL = 'SELECT FirstName, LastName, Phone from Members WHERE Email="'
. $tEmail . '" AND Password="' . $tPassword . '"';*/
$secureSQL = 'SELECT FirstName, LastName, Phone from Members WHERE Email="'
. $tEmail . '" AND AES_DECRYPT(Password, $passkey) ="' . $tPassword . '"';
//echo $secureSQL . "<br>";
// estalish SQL query
$STH = $DBH->query($secureSQL);
# setting the fetch mode -- this comes into effect when the fetch() function is called
$STH->setFetchMode(PDO::FETCH_ASSOC);
while($row = $STH->fetch()) {
$validUser = true;
$_SESSION['SAFEUSER'] = true;
}
if($validUser==false) {
echo "<font color='red'>Those credentials were not authenticated.</font><br/><br/>";
}
}
// are they logged in?
if(!$_SESSION['SAFEUSER']) {
// if not, make them login
?>
Please enter your credentials:<br />
<form method="post" action="mysecuremenu.php">
Your email address: <input type="text" name="Femail"><br>
Your password: <input type="password" name="Fpassword"></br>
<input type="submit" name="Fsubmit" value="lookupnow">
</form>
<?php
} else {
// otherwise, show them the menu
?>
<h2>Please select one of the following:</h2>
<ul>
<li><a href="MySecureFirstDBForm.php">Enter a new employee</a></li>
<li><a href="mySecuredbviewall_withdatatable.php">View all employees</a></li>
<li><a href="mysecuremenu.php?cmd=logout">Logout</a></li>
</ul>
<?php
} // end if(safeuser)
?>
</body>
</html>
I get this error:
Fatal error: Call to a member function setFetchMode() on a non-object on line 58
I feel like it has to have something to do with my SELECT statement because the one I have commented out above it works fine for logging in with non-encrypted passwords. I would appreciate any and all help. Thanks!