Forum Moderators: coopster

Message Too Old, No Replies

Problem with cookies

It is not authenticating correctly

         

romzinho2k7

6:44 am on Apr 24, 2006 (gmt 0)

10+ Year Member



People, I am with a problem very large.

I developed a site and yesterday, accessing him, saw that it owns a bug.

Authenticate system is via cookies, it owns 3 cookies, one with the user name, other with the password and another with the iD. However if change cookie( name ) he changes the user name and lets the same continues navigating with login that wish( and until post goods as if it was other person )

Below it follows the code that I did and that is not working:

<?
include("db.php");
$user = @$_COOKIE["user"];
$pass = @$_COOKIE["pass"];
$id = @$_COOKIE["id"];

$query = mysql_query("SELECT * FROM users WHERE BINARY id='$id' AND user='$user' AND pass='$pass' LIMIT 1");
if(!$query){
setcookie("id");
setcookie("user");
setcookie("pass");
header("Location: /");
}
?>

Would anybody know to help?

Anybody know some security site in files PHP? With tutorials, hints, etc? When I do a site for customers, I am afraid to of being invaded and the customer thinks I am incompetent :(

At once I thank.
Robson

hakre

11:52 am on Apr 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi!

Anybody know some security site in files PHP? With tutorials, hints, etc? When I do a site for customers, I am afraid to of being invaded and the customer thinks I am incompetent

i see. you should start at php.net when you can read and understand english quite ok, otherwise there should be sites linked in your own language there. just browse a bit around there.

it might be a good advise for your to get in touch with a php usergroup next to your city. checkout your countries php related page here:
[php.net...]

i don't want to be harsh so please don't be offended, but even the small piece of code you provided here has got serious security issues and should not be used unchanged. if you really want to professionally offer your php code you should get in contact with a webapplication / php security consult. i guess you already thought so by asking for a security site here. one start for that specific thing might be [phpsec.org...] which contains some articles to read through.

romzinho2k7

2:37 am on Apr 26, 2006 (gmt 0)

10+ Year Member



Hey,

Will it it be what anybody could help? I do not manage to develop a login system safe. A script for I look would be a good option... Help me please

hakre

11:04 am on Apr 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



the approach i would take:

  • use php session functionality [php.net]
  • create a login form and use the forms data to check wether or not the user can log in (i think you already did this).
  • when the user can log in, set a session variable that the user is authenticated (that's the part with the db like you did it, just use $_POST[] here) - this can be checked on password protected pages later on.

    for sessions your users only need to have cookies enabled (there is workaround for no-cookies even).

    the code you provided uses cookies directly which is a bit unsafe. with sessions, only the sessionid is saved in a cookie and the data according to it remains on the server only. so this can not be that easy manipulated and is more safe.

  • jatar_k

    5:11 pm on Apr 26, 2006 (gmt 0)

    WebmasterWorld Administrator 10+ Year Member



    try this post as well
    [webmasterworld.com...]

    romzinho2k7

    8:23 pm on Apr 26, 2006 (gmt 0)

    10+ Year Member



    Thank you very much hakre and jatar_k!

    Now already of the to search tutorials about that and to read post that jatar_k put.

    That safety subject is very important because if anybody invade the site the problem is not to erase the data ( that a backup solves ) but the site image gets a little burnt. An aspect of insecurity.

    Sorry my english.

    But thank you very much.
    Robson