Return to Snippet

Revision: 19002
at October 14, 2009 03:08 by FazzyX


Initial Code
private function genPassword() {
	  //Generate password
	  $letter    = array("a", "b", "c", "d", "e", "f", "g", "h", "k", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
	  $numbers        = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "0");
	  $specialCharacters = array("#", "!", "%");
	  $lenght = 8;
	  
	  for($i=0, $password=""; strlen($password)<$lenght; $i++)
	  {
		  if(rand(0, 2)==0 && isset($letter))
		  {
			  $password.=$letter[rand(0, count($letter))];
		  }
		  elseif(rand(0, 2)==1 && isset($numbers))
		  {
			  $password.=$numbers[rand(0, count($numbers))];
		  }
		  elseif(rand(0, 2)==2 && isset($specialCharacters))
		  {
			  $password.=$specialCharacters[rand(0, count($specialCharacters))];
		  }
	  }
	  
	  
	  
	  $md5Hash = md5($password);
	  // Create object for further use. Depend on Password Class
	  $oPassword = new Password('',$md5Hash,$password);
	  return $oPassword;
	}

Initial URL

                                

Initial Description
Generate random plain and md5 password. Depend on Password Class

Initial Title
Password Function

Initial Tags
php

Initial Language
PHP