Hi!
This post seems to be the closest (and most recent) to the issue I am currently having.
I have three pages involved:
1) Register page (register.php) - enters a users' info into the database. It encrypts the user-selected password like this:
function process_form(){
session_start();
$loginname=trim(strip_tags($_POST['username']));
$pswd=trim(strip_tags($_POST['password']));
$password=md5($pswd);
$_SESSION['auth']="yes";
global $db;
$today = getdate();
$db->query('INSERT INTO customers (firstname, lastname, username, password, date, type)
VALUES (?,?,?,?,?,?)',
array($_POST['firstname'],$_POST['lastname'], $_POST['username'], $password, $today, 'empe'));
PS: The "get date" doesn't seem to work for me either, but I'm not worring about that right now...
2) The login page is called index.html. It grabs the password with a simple "password" input field in a POST form which has an action of "login.php":
<input name="password" type="password" id="password" size="20" />
3) The login script called login.php - this page takes the users' password entered on the index page and sends a query to the database thus:
function process_form(){
global $db;
$loginname=trim(strip_tags($_POST['username']));
$pswd=trim(strip_tags($_POST['password']));
$password=md5($pswd);
//grab info from database
$userGroup = $db->get_results("SELECT type
FROM customers
WHERE (username='$logincookie[user]' or username='$loginname') and (md5(password)='$logincookie[pwd]' or password='$password')",ARRAY_A);
So the passwords in my database are nicely coded with the md5 process.
6 | empe | Sally | Sand | ssand | 3afc79b597f88a72528e864cf81856d2 | 0000-00-00 00:00:00
However, when I look at the query results from my login script, the password is not coded. I'm guessing that this is why my query doesn't give me any results.
Query [1] -- [SELECT type FROM customers WHERE (username='' or username='ssand') and (md5(password)='' or md5(password)='pass3')]
Query Result..
(row) string 0
type
No Results
However, I don't know how to fix the code so that it will work properly. I know that md5 is supposed to be a 'one way street' but I can't seem to figure out the proper way to use it in a query.
Please help! 😕
Thanks!
eCat