- function random_readable_pwd ($length =10) {
- The wordlist from which the password gets generated
- (change them as)
- $words = ' Dog,cat,sheep,sun,sky,red,ball,happy,ice, ';
- $words. = ' Green,blue,music,movies,radio,green,turbo, ';
- $words. = ' Mouse,computer,paper,water,fire,storm,chicken, ';
- $words. = ' Boot,freedom,white,nice,player,small,eyes, ';
- $words. = ' Path,kid,box,black,flower,ping,pong,smile, ';
- $words. = ' coffee,colors,rainbow,plus,king,tv,ring ';
- Split by ",":
- $words = Explode (', ', $words);
- if (count ($words) = = 0) {die (' Wordlist is empty! ');}
- Add words while password is smaller than the given length
- $pwd = ";
- while (strlen ($PWD) < $length) {
- $r = Mt_rand (0, Count ($words)-1);
- $pwd. = $words [$r];
- }
- Append a number at the end if length > 2 and
- Reduce the password size to $length
- $num = Mt_rand (1, 99);
- if ($length > 2) {
- $pwd = substr ($pwd, 0, $length-strlen ($num)). $num;
- } else {
- $pwd = substr ($pwd, 0, $length);
- }
- return $pwd;
- }
- Examples of Use:
- Random_readable_pwd (10)
- = = Returns something Like:pingwater6, RADIOHAP28, sunwhite84, happykid44, etc ...
Copy Code
|