How to generate random password in php

  1. function get_randomString($count=8, $rm_similar = false){
  2.  //create list of characters
  3.  
  4.  $chars = array_flip(array_merge(range(0, 9), range('A', 'Z')));
  5.  
  6.  // remove similar looking characters that might cause confusion
  7.  if ($rm_similar) {
  8.   unset($chars[0], $chars[1], $chars[2], $chars[5], $chars[8], $chars['B'],
  9.     $chars['I'], $chars['O'], $chars['Q'], $chars['S'], $chars['U'], $chars['V'], $chars['Z']);  
  10.  }
  11.  
  12.  // generate the string of random text
  13.  
  14.  for( $i = 0, $text = '';  $i < $count; $i++ ) {
  15.   $text .= array_rand($chars);
  16.  }
  17.  return $text;
  18. }

,

  1. No comments yet.
(will not be published)
Submit Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Subscribe to comments feed
  1. No trackbacks yet.

SetPageWidth