Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-23-2008, 05:12 PM   PM User | #1
Jon W
Regular Coder

 
Join Date: Jan 2008
Posts: 334
Thanks: 9
Thanked 0 Times in 0 Posts
Jon W is an unknown quantity at this point
PHP Login

I can't seem to get this PHP Login Script to work right. Its not doing what its suppose to be doing. When I type in a Username that is in the Database, it comes up and says: 'Invalid Username or Password'. I can't make sense of it and I don't have enough knowledge yet to know what I'm doing wrong. If someone could help me out that would be great. Thanks guys!

Jon W

PHP Code:

<?php

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

$username mysql_real_escape_string($_POST['username']);
$password mysql_real_escape_string(md5($_POST['password']));

include(
'db.php');

$query mysql_query("SELECT user_id, username, password, active FROM users WHERE username = '$username' AND password = '$password'") or die('Database Error: ' mysql_error());

$row mysql_fetch_assoc($query);
$check mysql_num_rows($query);

if(
$check == 1) {

if(
$row['active'] == 1) {


session_register($username);
session_register($password);

header("Location: http://example.com/index.php?user_id=" $row['user_id'] . "");
} else {

$error "Please Activate your account before logging in.";
 
} } else { 

$error "Invalid Username or Password";

} }

?>
Jon W is offline   Reply With Quote
Old 01-23-2008, 05:18 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
The username and password isn't in your users table. This script runs the password through md5(), which is officially cracked so therefore pretty useless.

How did you enter your username/password in your table? Is the password just plain text? If so, that's your problem.
__________________
Fumigator is offline   Reply With Quote
Old 01-23-2008, 05:19 PM   PM User | #3
Jon W
Regular Coder

 
Join Date: Jan 2008
Posts: 334
Thanks: 9
Thanked 0 Times in 0 Posts
Jon W is an unknown quantity at this point
Nope, the password is md5 in the database.
Jon W is offline   Reply With Quote
Old 01-23-2008, 05:21 PM   PM User | #4
runnerjp
Regular Coder

 
Join Date: Nov 2006
Posts: 601
Thanks: 1
Thanked 2 Times in 2 Posts
runnerjp can only hope to improve
md5 or not still should work.. you 100% sure its right why not try makin anouther udrname and password seeing if the works
runnerjp is offline   Reply With Quote
Old 01-23-2008, 05:23 PM   PM User | #5
Jon W
Regular Coder

 
Join Date: Jan 2008
Posts: 334
Thanks: 9
Thanked 0 Times in 0 Posts
Jon W is an unknown quantity at this point
Alright, well I'll try that and I'll let you guys know if that works or not.
Jon W is offline   Reply With Quote
Old 01-23-2008, 05:26 PM   PM User | #6
Jon W
Regular Coder

 
Join Date: Jan 2008
Posts: 334
Thanks: 9
Thanked 0 Times in 0 Posts
Jon W is an unknown quantity at this point
Yeah, its still doing the same thing as it was with the other Username. So its not making sense to me.
Jon W is offline   Reply With Quote
Old 01-23-2008, 05:49 PM   PM User | #7
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
Try running the query outside the PHP environment, for example using phpMyAdmin and see what you get. When I say run that query, I mean exactly the same query, which means you'll need to assign the query value to a variable, echo it, then copy/paste it and run it in phpMyAdmin. In other words, don't assume anything about the query.
__________________
Fumigator is offline   Reply With Quote
Old 01-23-2008, 06:10 PM   PM User | #8
runnerjp
Regular Coder

 
Join Date: Nov 2006
Posts: 601
Thanks: 1
Thanked 2 Times in 2 Posts
runnerjp can only hope to improve
where didi you get your code from?
runnerjp is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:38 PM.


Advertisement
Log in to turn off these ads.