1

Topic: random pass

Now actual 1.2 code

//
// Generate a random password of length $len
//
function random_pass($len)
{
    $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

    $password = '';
    for ($i = 0; $i < $len; ++$i)
        $password .= substr($chars, (mt_rand() % strlen($chars)), 1);

    return $password;
}

Maybe better:

function random_pass () {
    $length ="8";              // the length of the password required
    $possible = '23456789abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
    $str ="";

    while (strlen($str) < $length) {
        $str.=substr($possible, (rand() % strlen($possible)),1);
    }

    return($str);
}

//  Adapted from code by the following author:
//
//   Author: mr.shifter@hosted.uklinux.net
//   http://www.hosted.uklinux.net/php/freescripts/index.php
//
//       All Rights Reserved Free to use don't abuse
//   PLEASE NOTE:The numbers 0 and 1 (zero and one) and the letters
//   l and o, ('el' and 'oh' in lowercase) and the letters I and O
//   ('eye' and 'oh' in uppercase) have been removed from the random
//   generator, so as not to cause confusion when writing them down.

Re: random pass

whats the advantage? apart from a few letters missing

Re: random pass

Yes, I'm curious. How is that any better? If anything, I would say it is worse (mainly because it uses rand() and not mt_rand()).

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: random pass

1 N and l are missing....

5

Re: random pass

paolo wrote:

//   generator, so as not to cause confusion when writing them down.

Re: random pass

then just take those letters out of rickards generator....

7

Re: random pass

Connorhd wrote:

then just take those letters out of rickards generator....

Yes, that was my idea.
Having no time I've just copied it all smile