note 76613 added to function.md5

From: Date: Mon, 23 Jul 2007 09:33:55 +0000
Subject: note 76613 added to function.md5
Groups: php.notes 
Request: Send a blank email to php-notes+get-128832@lists.php.net to get a copy of this message
@ me at dontemailme dot com Your code takes ages to run mainly because it uses totally random characters, which in some cases don't exist because you have used chr() and rand() which can output very large numbers. I think most people only use alphanumeric passwords so here is a code which is far quicker. Where yours took 16 seconds mine took 2. It still takes ages for large passwords though which is reassuring! Also a hacker shouldn't know the password length meaning that the passwords are very secure with hashing. <?php set_time_limit(0); function randomkeys($length) { $pattern = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; $key = $pattern{rand(0,61)}; for($i=1;$i<$length;$i++) { $key .= $pattern{rand(0,61)}; } return $key; } if (isset($_GET['password'])){ $password = $_GET['password']; $password_length = strlen($password); } else { $password_length = 3; if (isset($_GET['length'])){ $password_length = $_GET['length'];} $password = randomkeys($password_length); } echo "Password is: $password <br />"; $password = md5($password); $attempts = 0; $start = microtime(true); while ($password != $guess){ $guess = md5(randomkeys($password_length)); $attempts++; } $end = microtime(true); $time = $end-$start; echo "Password guessed correctly after $attempts attempts and $time seconds"; ?> I think this code is correct but hopefully someone will tell me if it isn't or change it. ---- Server IP: 194.145.210.3 Probable Submitter: 86.112.240.37 ---- Manual Page -- http://www.php.net/manual/en/function.md5.php Edit -- https://master.php.net/note/edit/76613 Del: integrated -- https://master.php.net/note/delete/76613/integrated Del: useless -- https://master.php.net/note/delete/76613/useless Del: bad code -- https://master.php.net/note/delete/76613/bad+code Del: spam -- https://master.php.net/note/delete/76613/spam Del: non-english -- https://master.php.net/note/delete/76613/non-english Del: in docs -- https://master.php.net/note/delete/76613/in+docs Del: other reasons-- https://master.php.net/note/delete/76613 Reject -- https://master.php.net/note/reject/76613 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128832) next »