note 57409 added to function.mt-rand

From: Date: Mon, 03 Oct 2005 14:18:15 +0000
Subject: note 57409 added to function.mt-rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-96295@lists.php.net to get a copy of this message
My try at generating a reasonably secure password: <?php function keygen() { $tempstring = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO PQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABC DEFGHIJKLMNOPQRSTUVWXYZ!?@#$%&*[]{}();:,<>~+=-_ /|\\"; for($length = 0; $length < mt_rand(10, 15); $length++) { $temp = str_shuffle($tempstring); $char = mt_rand(0, strlen($temp)); $pass .= $temp[$char]; } return $pass; } echo(keygen()); echo("\n"); ?> This generates a password of an undefined length (in this case, 10 to 15 chars) consisting of numbers, UPPERCASE letters lowercase letters and a set of signs. I have doubled the chance of number and letters to reduce the confusion with my users. ---- Manual Page -- http://www.php.net/manual/en/function.mt-rand.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57409 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57409&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57409&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57409&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57409&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57409&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57409&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57409&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57409&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#96295) next »