note 43110 deleted from function.rand by tomsommer
| From: | tomsommer@php.net | Date: | Wed, 09 Jun 2004 21:58:22 +0000 |
| Subject: | note 43110 deleted from function.rand by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-70626@lists.php.net to get a copy of this message | ||
Note Submitter: seanvasey@icefusionmedia.com
----
Here is a quick and easy way to generate a random password. This was taught to me by a friend and I
feel that it is a rather creative way to creat a random password with a mix of letters and numbers.
<?php
$rand = rand(1, 999999999); //random number 1-999999999
$md5string= md5($rand); //create md5 of random number
$string = substr($md5hash, 0, 10); //cut the hash to 10 characters
$newpass = $string; // 10 digit random password of numbers nad letters
$md5_newpass = md5($newpass); //create md5 for updating user account in database.
?>
As you can see, it md5 encrypts a random number in order to get a random combination of numbers and
letters. The substr() function is then used to cut the md5 hash from 30 to 10 characters. This is a
quick, easy, creative, and secure way to create a random password.