note 86762 added to function.md5

From: Date: Sun, 02 Nov 2008 18:06:22 +0000
Subject: note 86762 added to function.md5
Groups: php.notes 
Request: Send a blank email to php-notes+get-146062@lists.php.net to get a copy of this message
I usually MD5 the username, password and IP to set login cookie. MD5ing IP will make cookie thief on other computers fail. <?php //... connect to database, load list of users, etc... $username = $_POST['username']; $password = $_POST['password']; /* $cookie may look like this: variables $username = "username" $password = "password" _SERVER['REMOTE_ADDR'] = 42.52.56.24 before md5: "usernamepassword42.52.56.24" after md5: "a3470ce826283eca7ce3360d0f26b230" */ $cookie = md5 ( $username . $password . $_SERVER['REMOTE_ADDR'] ); setcookie ("login", $cookie); //when the log in cookie is SET... if (isset($_COOKIE['login']) ) { foreach ($user_list as $user => $pass) { //match the user list with the cookie if ( md5 ( $user . $password . $_SERVER['REMOTE_ADDR'] ) == $_COOKIE['login'] ) { header("Location: index.php"); die("logged in"); } } //when login is wrong header("Location: login.php"); die("wrong username/password"); } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 70.71.75.169 ---- Manual Page -- http://www.php.net/manual/en/function.md5.php Edit -- https://master.php.net/note/edit/86762 Del: integrated -- https://master.php.net/note/delete/86762/integrated Del: useless -- https://master.php.net/note/delete/86762/useless Del: bad code -- https://master.php.net/note/delete/86762/bad+code Del: spam -- https://master.php.net/note/delete/86762/spam Del: non-english -- https://master.php.net/note/delete/86762/non-english Del: in docs -- https://master.php.net/note/delete/86762/in+docs Del: other reasons-- https://master.php.net/note/delete/86762 Reject -- https://master.php.net/note/reject/86762 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#146062) next »