RE: [PHP-WIN] Password generator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Create a string which is six char long,
(for instance shop the head and tail
of the first string if you are not able
to generate a six char string)

If you chop an 8 char string and MUST have
the special chars in the string then check
that the chopped char's is not a memember of
the special char's- If they are, regenerate a
new string an loop until they are not

Finally randomize the head and the tail with
you "custom" algorithm. E.g. an algoritm that
does not contain your 


Med vanliga halsningar fran Amsterdam. =) ;)


-----Original Message-----
From: Davy Obdam
To: PHP; PHP-WIN; PHP-DB
Sent: 2003-06-17 11:45
Subject: [PHP-WIN] Password generator

Hi people,

I have to make a password generator, but i have a little problem.

- It needs to generate password 8 characters long, and including 1 or 2 
special characters(like #$%&*@).
- Those special characters can never appear as the first or last 
character in the string... anywhere between is fine.

I have a password generator script now that does the first thing... but 
the special character can be in front or back of the string wich it 
shouldnt.. i have been looking on the web for this but i havent found 
the answer. Below is my scripts so far.. 

Any help is appreciated, thanks for your time,

Best regards,

Davy Obdam

------------------------------------------------------------------------
----------------------------------------

<?php
// A function to generate random alphanumeric passwords in PHP
// It expects to be passed a desired password length, but it
// none is passed the default is set to 8 (you can change this)
function generate_password($length = 8) {

    // This variable contains the list of allowable characters
    // for the password.  Note that the number 0 and the letter
    // 'O' have been removed to avoid confusion between the two.
    // The same is true of 'I' and 1
    $allowable_characters =
"abcdefghefghijklmnopqrstuvwxyz0123456789%#*&";
   
    // We see how many characters are in the allowable list
    $ps_len = strlen($allowable_characters);

    // Seed the random number generator with the microtime stamp
    // (current UNIX timestamp, but in microseconds)
    mt_srand((double)microtime()*1000000);

    // Declare the password as a blank string.
    $pass = "";

    // Loop the number of times specified by $length
    for($i = 0; $i < $length; $i++) {
   
        // Each iteration, pick a random character from the
        // allowable string and append it to the password.
        $pass .= $allowable_characters[mt_rand(0,$ps_len-1)];
   
    }

    // Retun the password we've selected
    return $pass;
}

$password = generate_password();
echo $password;

?>

-- 
-----------------------------------------------------------------------
Davy Obdam 
Web application developer

Networking4all
email: d.obdam@networking4all.com
email: info@davyobdam.com
internet: http://www.networking4all.com
-----------------------------------------------------------------------




-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux