Zend - The PHP Company




Passwords

Add Code


Auto Password Generation  

Type: code fragment
Added by: santos_raj
Entered: 31/05/2002
Last modified: 06/12/2001
Rating: **** (12 votes)
Views: 12975
This code scriptlet will generate passwords comprising of numerals, alphabates and underscore of varying length.


/*********************************************
***** Author Santosh
***** email santos_raj@yahoo.com,
        santos_raj@rediffmail.com,
        santosh_kumarsingh@hotmail.com
***** just copy the code and paste. Save this 
***** as a php file. run the url at the browser
***** and that is all.
**********************************************/
<?php
$min
=4;// minimum length of password
$max=15;// maximum length of password
$pwd="";   //to store generated password
for($i=0;$i<rand($min,$max);$i++){
    
$num=rand(48,122);
    if((
$num 97 && $num 122)){
        
$pwd.=chr($num);
    }else if((
$num 65 && $num 90)){
            
$pwd.=chr($num);
    }else if((
$num >48 && $num 57)){
            
$pwd.=chr($num);
    }else if(
$num==95){
        
$pwd.=chr($num);
    }else{
        
$i--;
    }
}
echo 
$pwd;// prints the password
?>


Usage Example




Rate This Script





Search



This Category All Categories