note 71921 added to function.setcookie

From: Date: Fri, 22 Dec 2006 19:31:20 +0000
Subject: note 71921 added to function.setcookie
Groups: php.notes 
Request: Send a blank email to php-notes+get-120857@lists.php.net to get a copy of this message
If you want use setcookie for login(remember me cookie),you must use MD5() or Sha1() for encoding data: <?php $username = $_POST['username']; $password = sha1($_POST['password']); /* Hash the input password and check it against the already hashed password stored in the database. Since both passwords are hashed using the same hash function, the two passwords will match if the user enteres the correct password */ $user = $DB->getRow('SELECT * FROM users WHERE username=? AND password=?', array($username, $password)); if(!$user) die('Sorry, incorrect username or password.'); // Did this user check that 'remember me' checkbox? if($_POST['remember_me']) { $expire = time() + 1728000; // Expire in 20 days $cookie_pass = sha1( sha1($useSince both passwords are hashed using the same hash function, the two passwords will match if the user enteres the correct password */ $user = $DB->getRow('SELECT * FROM users WHERE username=? AND password=?', array($username, $password)); if(!$user) die('Sorry, incorrect username or password.'); // Did this user check that 'remember me' checkbox? if($_POST['remember_me']) { $expire = time() + 1728000; // Expire in 20 days $cookie_pass = sha1( sha1($user['password']) . sha1($user['salt']) ); setcookie('user', $user['username'], $expire); setcookie('pass', $cookie_pass, $expire); } ?> ---- Server IP: 84.47.204.3 Probable Submitter: 82.99.243.141 ---- Manual Page -- http://www.php.net/manual/en/function.setcookie.php Edit -- https://master.php.net/note/edit/71921 Del: integrated -- https://master.php.net/note/delete/71921/integrated Del: useless -- https://master.php.net/note/delete/71921/useless Del: bad code -- https://master.php.net/note/delete/71921/bad+code Del: spam -- https://master.php.net/note/delete/71921/spam Del: non-english -- https://master.php.net/note/delete/71921/non-english Del: in docs -- https://master.php.net/note/delete/71921/in+docs Del: other reasons-- https://master.php.net/note/delete/71921 Reject -- https://master.php.net/note/reject/71921 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120857) next »