Php > Miscellaneous
Password Generation Function
Password Generation Function @\_'; } # Find the charset length $charset_length = strlen($valid_charset); # If no chars is allowed, return false if ($charset_length == 0) return false; # Initialize the password and loop till we have all $password = ""; while(strlen($password) < $length) { # Pull out a random char $char = $valid_charset[mt_rand(0, ($charset_length-1))]; # If similar is true, check if string contains mistakeable chars, add if accepted if (($fix_similar && !strpos('O01lI5S', $char)) || !$fix_similar) $password .= $char; } # Return password return $password; } function password_generate_pronouncable($length = 8) { # Initialize valid char lists $valid_consonant = 'bcdfghjkmnprstv'; $valid_vowel = 'aeiouy'; $valid_numbers = '0123456789'; # Find the charset length $consonant_length = strlen($valid_consonant); $vowel_length = strlen($valid_vowel); $numbers_length = strlen($valid_numbers); # Initialize the password and loop till we have all $password = ""; while(strlen($password) < $length) { # Pull out a random set of pronouncable chars if (mt_rand(0, 2) != 1) $password .= $valid_consonant[mt_rand(0, ($consonant_length-1))].$valid_vowel[mt_rand(0, ($vowel_length-1))].$valid_consonant[mt_rand(0, ($consonant_length-1))]; else $password .= $valid_numbers[mt_rand(0, ($numbers_length-1))]; } return substr($password, 0, $length); } ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage