Password field
Posted by: Cristal (---.user.veloxzone.com.br)
Date: March 07, 2009 11:38AM

Hello ...


Why this does not work with my wamp ?

select from users where password = "youcango";

I receive : Empty set (0.00 sec)

Then I tryed this too:

select from users where password = password("youcango"winking smiley;

I receive: Empty set (0.00 sec)


thank you for your help

Options: ReplyQuote
Re: Password field
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: March 07, 2009 04:49PM

where are you writing this?
post up the code?

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Password field
Posted by: yfastud (Moderator)
Date: March 07, 2009 05:58PM


Options: ReplyQuote
Re: Password field
Posted by: Cristal (---.user.veloxzone.com.br)
Date: March 07, 2009 06:41PM

Ok, let me explain a little bit.

I doing a login page, and this is only part of my code, I created a dabase, table etc...:and I can connect to the table without problem.

<?php

session_start();


$errorMessage = '';

if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {
include 'config.php';
include 'opendb.php';

//$userId = $_POST['txtUserId'];
//$password = $_POST['txtPassword'];

}
// user_id = itisme and password = youcango, just to test
$sql= ("SELECT * FROM tbl_auth_user WHERE user_id = 'itisme'
AND user_password = password('youcango')"winking smiley;

$res = mysql_query($sql) or die (mysql_error());
$total = mysql_num_rows($res);
echo "$total";

include 'closedb.php';

?>

I should receive $total =1 if everything is ok, name and password, but I allways receive $total = 0.

So, I went to Mysql Console and tryed:
select from users where password = "youcango"; or

select from users where password = password("youcango"winking smiley;

and I receive allways:

Empty set (0.00 sec), If I receive Empty set here, I will receive $total=0

Of course I selected, the database, table etc...in Mysql Console.


if you want the code for include 'config.php'; include 'opendb.php'; and include 'closedb.php'; I can post here.

Thank you,

Options: ReplyQuote
Re: Password field
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: March 07, 2009 06:42PM

<?php

session_start();



you have a gap
it needs to be

<?php
session_start();




session is very strict on any whitespace

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Password field
Posted by: c2dan (---.sotn.cable.ntl.com)
Date: March 07, 2009 06:55PM

stevenmartin99 Wrote:
-------------------------------------------------------
> <?php
>
> session_start();
>
>
>
> you have a gap
> it needs to be
>
> <?php
> session_start();
>
>
>
>
> session is very strict on any whitespace

Not within php tags its not.

@Cristal how have you inserted the password into your tbl_auth_user table?

Options: ReplyQuote
Re: Password field
Posted by: yfastud (Moderator)
Date: March 07, 2009 07:01PM

actually, to rephrase what c2dan stated, did you create db account? if not, follow this
[blog.jlbn.net]

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: Password field
Posted by: Cristal (---.user.veloxzone.com.br)
Date: March 07, 2009 07:45PM

Thank you for the answers.

I removed the extra whitespaces and I have the same problem.
Yes I created a db account.

I verified that in my table the field user_password has something like *D37C40049.........., and not youcango.

So, I added the lines:

$password= md5("youcango"winking smiley
echo "$password";

and I have another number like 00F7C1........... that is different from the number that I have in my database field user_password, I think the problem is the encription type that is in my sql table.

Thank you,

Options: ReplyQuote
Re: Password field
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: March 07, 2009 07:47PM

do u have white space at the top? befoere the <?php

the file shud be



-----------------------------------------------topline
<?php

session

is what i ment to say

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Password field
Posted by: Cristal (---.user.veloxzone.com.br)
Date: March 07, 2009 08:15PM

Ok, I solved the problem:

To insert data in my table I used:

Insert into ´mytable´ (´user_id´, ´user_password´) values (´itisme´, md5(´youcango´);


and I modify the line to :

$password =("youcango"winking smiley; //later I will modify to $password = $_POST['txtPassword'];

$sql= ("SELECT * FROM tbl_auth_user WHERE user_id = 'itisme'
AND user_password = md5(´password´)"winking smiley;

Now I have everything working talking the same language (md5).

Thank you for your time and support.

Options: ReplyQuote
Re: Password field
Posted by: c2dan (---.sotn.cable.ntl.com)
Date: March 07, 2009 08:15PM

Cristal Wrote:
-------------------------------------------------------
> Thank you for the answers.
>
> I removed the extra whitespaces and I have the
> same problem.
> Yes I created a db account.
>
> I verified that in my table the field
> user_password has something like
> *D37C40049.........., and not youcango.
>
> So, I added the lines:
>
> $password= md5("youcango"winking smiley
> echo "$password";
>
> and I have another number like 00F7C1...........
> that is different from the number that I have in
> my database field user_password, I think the
> problem is the encription type that is in my sql
> table.
>
> Thank you,

Seems you have setup your password field incorrectly. For MD5 encryption you should set your field up as VARCHAR(32)


To fix this open phpmyadmin select your database then find your tbl_auth_user table. Click the operations tab and select the EMTPY tab. This will clear you table.

Next select the structure tab. Find the password field and click then pencil icon next to it. Now find the TYPE field and select VARCHAR and enter 32 for the LENGTH. Click Go.

Now click the INSERT tab to insert a new record. When you get to the password field select MD5 from the FUNCTIONS column and now enter your password. Click Go when finished.

Now in your script use this:
<?php
session_start();

include 'config.php';
include 'opendb.php';

$errorMessage = '';

if (isset($_POST['txtUserId']) && isset($_POST['txtPassword']))
{
$userId = mysql_real_escape_string($_POST['txtUserId']);

// encrypt the password before using it in the query
$password = md5($_POST['txtPassword']);

$sql= "SELECT * FROM tbl_auth_user WHERE user_id = '$userId' AND user_password = '$password'";
$res = mysql_query($sql) or die (mysql_error());

echo mysql_num_rows($res);
}

include 'closedb.php';

?>

Options: ReplyQuote
Re: Password field
Posted by: Cristal (---.user.veloxzone.com.br)
Date: March 07, 2009 08:33PM

Thank you very much c2dan. It works.

Options: ReplyQuote


Sorry, only registered users may post in this forum.