Password generator

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

 



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 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