WebMe
homeaboutportfolioservicescontact

WebMe - Website Design & Development

previous posts
archives
 

All resources published on this blog are free to use and redistribute. All we ask is that you keep any copyright notices and links to WebMe in your code. If you find something really useful we would appreciate you placing a link on your site to ours.

 
uk web design association Independent Web Developers Portal
This is a Carbon Neutral website Follow us on Twitter
All major credit cards accepted
Web Site Design BlogSubscribe to this Blog

Random Password Generator in PHP

Today we thought we'd share our random PHP password generator code with you. This function returns a variable length password comprised of upper and lower case characters with numbers. Simply pass the desired password length to the function.
function RandomPW($myLength) {
 $strPW = '';
 //These constant are the minimum and maximum length for random
 //length passwords.  Adjust these values to your needs.
 $minLength = 6;
 $maxLength = 20;
 
 if ($myLength == 0) {
  $myLength = rand($minLength, $maxLength);
 }

 for ($X=1;$X<=$myLength;$X++) {
  //Randomize the type of this character
  $Y = rand(1,3); //(1) Numeric, (2) Uppercase, (3) Lowercase
  switch ($Y) {
   case 1:
    //Numeric character
    $strPW = $strPW.chr(rand(48, 57));
    break;
   case 2:
    //Uppercase character
    $strPW = $strPW.chr(rand(65, 90));
    break;
   case 3:
    //Lowercase character
    $strPW = $strPW.chr(rand(97, 122));
    break;
  }
 }
 return($strPW);
}

Labels: , ,

Design web site media

0 Comments:

Post a Comment

<< Home

 

info@webme.co.uk

copyright About UsServicesPortfolioDemoGet QuoteContact