Random Password Generator[PHP]

Discussion in 'Web Programming' started by Sprintâ„¢, Nov 18, 2011.

Random Password Generator[PHP]
  1. Unread #1 - Nov 18, 2011 at 9:30 PM
  2. Sprintâ„¢
    Joined:
    Nov 18, 2011
    Posts:
    8
    Referrals:
    0
    Sythe Gold:
    0

    Sprintâ„¢ Newcomer

    Random Password Generator[PHP]

    Generating a password with a combination of letters, alphabets and special chars, by default it generates 10 chars.

    ================================================

    Code:
    function RandomPasswordGeneration($passwordlength=10)
     {
     	// add numbers,alphabets and special chars
      	$random_chars = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%";
            $getstring = "";
    	$password= "";
    	// While loop will execute until the length of password reaches the $passwordlength
            while(strlen($password)<$passwordlength) 
    	{
    		 // returns a sigle character from the set of random_chars
    		 $getstring = substr($random_chars, mt_rand(0, strlen($random_chars)-1),1);
    		
    		 //Avoid already existed character from the password.
    		 if (!strstr($password, $getstring)) 
    		 {
    		     //append the generated value to password 
        		     $password .= $getstring;
        	         }
               }
        return($password);
    }
    
    echo "Random Password ".RandomPasswordGeneration(); 
    //if you need a length of 8 chars, send the paratmeter in function as RandomPasswordGeneration(8);
     
< HTACCESS Writer | Quick SQL Question >

Users viewing this thread
1 guest


 
 
Adblock breaks this site