Posts Tagged ‘random’

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. }

,

No Comments



SetPageWidth