dimanche 25 octobre 2015

Generate Random Password without these characters "l1o0"

I need to generate random password with condition:

  • All characters are allowable except "l1o0"
  • Length of 8 to 12 in characters

Codes I've tried:

function generateRandomPassword() {
  //Initialize the random password
  $password = '';

  //Initialize a random desired length
  $desired_length = rand(8, 12);

  for($length = 0; $length < $desired_length; $length++) {
    //Append a random ASCII character (including symbols)
    $password .= chr(rand(32, 126));
  }

  return $password;
}

How to avoid these 4 characters => "l1o0" ?

Reason:

  • These 4 characters are sometimes confused the user.

Thanks!




Aucun commentaire:

Enregistrer un commentaire