Md5 Login page problem!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DarkWolfXP
Forum Newbie
Posts: 3
Joined: Sat Jul 01, 2006 5:21 pm

Md5 Login page problem!

Post by DarkWolfXP »

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello this is my first post on this forum...
Here it go!
Ok I encrypted my password on the page Register.php
In login.php I  made script to encrypt the password and then look if does match or not with the Database
My problem is there they match but that not working well

Code: Select all

<?
include "configuration.php";

$db = mysql_connect($host, $login_php, $password);
$basedados = mysql_select_db($database);
$pass = md5($pass);
$check = mysql_query("SELECT * FROM `$table` WHERE login = '$login' AND pass = '$pass'", $db);
$count = mysql_num_rows($check); 

if ( $count == 1 ) {
   echo "Welcome User";
  } else {
  echo "Login fail";
}
?>
when I do echo "$count"; give me always 0 with the password

What I am doing wrong?


Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by DarkWolfXP on Sun Jul 02, 2006 2:54 am, edited 1 time in total.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Re: Md5 Login page problem!

Post by tecktalkcm0391 »

DarkWolfXP wrote:Hello this is my first post on this forum...
Here it go!
Ok I encrypted my password on the page Register.php
In login.php I made script to encrypt the password and then look if does match or not with the Database
My problem is there they match but that not working well
<?
include "configuration.php";

$db = mysql_connect($host, $login_php, $password);
$basedados = mysql_select_db($database);
$pass = md5($pass);
$check = mysql_query("SELECT * FROM `$table` WHERE login = '$login' AND pass = '$pass'", $db);
$count = mysql_num_rows($check);

if ( count == 1 ) {
echo "Welcome User";
} else {
echo "Login fail";
}
?>
when I do echo "$count"; give me always 0 with the password

What I am doing wrong?
First MD5 is NOT encrypted as you can see here: viewtopic.php?p=270977. Second, where is $pass and $login coming from?
DarkWolfXP
Forum Newbie
Posts: 3
Joined: Sat Jul 01, 2006 5:21 pm

Hm

Post by DarkWolfXP »

thx for the encryption page :)
About $login $pass I folowed a tutorial and he didnt define that 2 strings :s
And now I see they are not defined can that be the problem?
I know $login is to the text field named 'login' and $pass to the text field 'pass'
How can I define that 2 strings to textfield?


P.S if I dont use md5 and copy the password on database it will show "Welcome user"
So I think they are defined to the textfields already.
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Post by William »

Well you could define $user and $pass to $_POST['user'] and $_POST['pass'] and then all you would have to do is setup your login form and set the name value of the inputs to user and pass. If this doesn't help post your login page also.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Your code should start out like this...

Code: Select all

<?php
include "configuration.php";

$db = mysql_connect($host, $login_php, $password);
$basedados = mysql_select_db($database);
// You really should be doing an if() check here instead of assuming
// but seeing this is a tutorial, lets assume, shall we?
$login = $_POST['login'];
$pass = md5($_POST['pass']);
$table = ''; //Set this value to the mysql table you are selecting from

$check = mysql_query("SELECT * FROM `$table` WHERE login = '$login' AND pass = '$pass'", $db);
$count = mysql_num_rows($check);

if ( $count == 1 ) {
    echo "Welcome User";
} else {
    echo "Login fail";
}
?> 
This is really not a good example of a login system. If I were you I would look through the code snippets forum on these boards for a tutorial by Maugrim_the_Reaper regarding login systems. But for the sake of testing, try the code above and see what comes of it.
DarkWolfXP
Forum Newbie
Posts: 3
Joined: Sat Jul 01, 2006 5:21 pm

Hm

Post by DarkWolfXP »

"login Fail" -.-
I go to Tutorial part and look some secure system this is anoying XD
thx for all ppl :)
U guys really fast answering :o
Really nice ^^
Thx all :)
Post Reply