- Function random_readable_pwd ($ length = 10 ){
- // The wordlist from which the password gets generated
- // (Change them as you like)
- $ 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 ",":
- $ 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;
- }
- // Example:
- Random_readable_pwd (10)
- => Returns something like: pingwater6, radiohap28, sunwhite84, happykid44, etc...
|