<?php /** This file is a contracted file from the PHP Friendly Password suggest package's classes **/class RandomString{protected $f,$str,$l,$p,$u,$a,$cn,$cm,$cl,$fm; public function __construct($l=11,$u=true,$f=[],$p='',$str='qwertyuiopasdfghjklmnbvcxz0123654789.*/-+`~@#$%^&()_=:;\'",./?{}|\\'){if(empty($str)||!is_string($str)) $str='qwertyuiopasdfghjklmnbvcxz0123654789.*/-+`~@#$%^&()_=:;\'",./?{}|\\';if(!empty($f)&&is_array($f)){$f=array_values($f);foreach($f as $k=>$v){if(!is_int($v)&&!is_array($v)&&$v!=='n') $f[$k]=0;elseif(!is_int($v)&&is_array($v)&&count($v)==2){$f[$k]=array_values($f[$k]); if(!is_int($f[$k][0]))$f[$k][0]=0;if(!is_int($f[$k][1]))$f[$k][1]=0;$f[$k]=rand($f[$k][0],$f[$k][1]);}if($k>2) unset($f[$k]);} }else{$f=[];} $this->f=$f=array_pad($f,3,0);$this->str=$str;if(!preg_match('#[0-9]#',$this->str)&&is_int($f[1])) $this->str .='0123654789';if(!preg_match('#[[:punct:]]#',$this->str)&&is_int($f[2]))$this->str .='.*/-+`~@#$%^&()_=:;\'",./?{}|\\'; $this->l=intval($l);$this->p=(is_numeric($p)||is_string($p))?$p:"";$this->u=(boolean)$u;list($this->cn,$this->cm,$this->cl)=$this->f; $this->a=$this->cn+$this->cm+$this->cl;if($this->a>$l) $this->fm=0;else $this->fm=$l-($this->a);if(!$u&&$this->a<$l&&$cn)$this->fm +=$cn; if(!preg_match('#[a-z]#i',$this->str)) $this->str .='qwertyuiopasdfghjklmnbvcxz';} public function ksi_uniq_value(){ $cs=['strtolower','strtoupper']; $i=strlen($this->p); $r=$this->p; $fm=0; $cnp=$this->cn; preg_match_all('#[A-Z]#',$r,$mt); if(($a=count($mt[0]))>0) $cnp=$cnp-$a; $cnp=$cnp<0?0:$cnp; $fm +=$a; $cmp=$this->cm; preg_match_all('#[0-9]#',$r,$mt); if(($a=count($mt[0]))>0) $cmp=$cmp-$a; $cmp=$cmp<0?0:$cmp; $fm +=$a; $clp=$this->cl; preg_match_all('#[[:punct:]]#',$r,$mt); if(($a=count($mt[0]))>0) $clp=$clp-$a; $clp=$clp<0?0:$clp; $fm +=$a; $fm +=$this->fm; $stl=strlen($this->str)-1; while($i<$this->l){ $ch=($this->u)?$cs[array_rand($cs)]($this->str{rand(0,$stl)}):$this->str{rand(0,$stl)}; if(ctype_alpha($ch)&&ctype_upper($ch)){ if($this->cn){ if($cnp) { if($cnp==='n'){ $cnp=0; continue; } $r .=$ch; $cnp--; $i++; continue; }elseif(!$cnp){ continue; } } } if($cmp&&ctype_digit($ch)){ if($cmp==='n'){ $cmp=0; continue; } $r .=$ch; $cmp--; $i++; continue; } if($this->cm&&!$cmp&&ctype_digit($ch)){ continue; } if($clp&&!ctype_alnum($ch)){ if($clp==='n'){ $clp=0; continue; } $r .=$ch; $clp--; $i++; continue; } if($this->cl&&!$clp&&!ctype_alnum($ch)){ continue; } else{ if($fm){ $r .=$ch; $i++; $fm--; } } } return $r; } } class FriendlyPwdSuggest{ protected $Rs,$f,$l,$dll; public function __construct($d,$l=12,$dd=null,$sd=false,$f=[[1,2],[1,3],[1,2]]){ if(!is_array($d)) throw new InvalidArgumentException ('$d must be of t array ,'.gettype($d).' given'); if(!is_int($l)) throw new InvalidArgumentException ('$l must be of t integer ,'.gettype($l).' given'); $l=($l>0)?$l:6; $d=array_values($d); foreach ($d as $k=>$v) if(!is_numeric($v)&&!is_string($v)) $v=''; $dd=(empty($dd)||!is_string($dd))?$_SERVER['SERVER_NAME']:$dd; if(substr_count($dd,'.')>=2) $dd=substr($dd,($fs=stripos($dd,'.')+1),(strripos($dd,'.')-$fs)); $f=array_values($f); if(!empty($f)&&is_array($f)){ $f=array_values($f); foreach($f as $k=>$v){ if(!is_int($v)&&!is_array($v)&&$v!=='n') $f[$k]=0; elseif(!is_int($v)&&is_array($v)&&count($v)==2){ $f[$k]=array_values($f[$k]); if(!is_int($f[$k][0]))$f[$k][0]=0; if(!is_int($f[$k][1]))$f[$k][1]=0; $f[$k]=rand($f[$k][0],$f[$k][1]); } if($k>2) unset($f[$k]); } }else{ $f=[]; } $this->f=$f=array_pad($f,3,0); if(!$sd){ $d[]=$dd; $d2=$d; shuffle($d2); $d2=join('',$d2); $d[]=$d2; unset($d2); $alt=[substr($d[array_rand($d)],0,rand(round($l/3),round($l/2))),substr($d[array_rand($d)],0,(abs($l-array_sum($f))))]; $dl=$alt[(array_rand($alt))]; if(strlen($dl)>$l) $dl=$alt[0]; }else{ $alt=[substr($dd,0,rand(round($l/3),round($l/2))),substr($dd,0,(abs($l-array_sum($f))))]; $dl=$alt[array_rand($alt)]; } $this->dll=strlen($dl); $d=implode('',$d); $this->l=$l; $this->Rs= new RandomString($this->l,true,[$f[0],(preg_match_all('#[0-9]#',$dl,$mt)?((($c=count($mt[0]))>=$f[1])?'n':($f[1]-$c)):$f[1]),(preg_match_all('#[[:punct:]]#',$dl,$mt)?((($d=count($mt[0]))>=$f[2])?'n':($f[2]-$d)):$f[2])],$dl,$d); } public function suggest($t='',$tS=false){ if(in_array('n',$this->f)){ $sg=$this->Rs->ksi_uniq_value();} else {while(!($sg=$this->only_strong($this->Rs->ksi_uniq_value(),$tS))){}} if(strtolower($t)==='json') return json_encode($sg); else return $sg; } public function suggest_n($n=5,$t='',$tS=false){ $n=(!is_int($n))?5:$n; $sg=[]; while($n>0){$sg[]=$this->suggest('',$tS);$n--;} if(strtolower($t)==='json')return json_encode($sg); else return $sg; } protected function only_strong($sg,$tS=false){ $cs=['strtolower','strtoupper']; if((preg_match('#[[:punct:]]#',$sg)&&preg_match('#[0-9]#',$sg)&&preg_match('#[A-Z]#',$sg))||$this->l<=6){ if(!$tS){ for($i=0;$i<=$this->dll;$i++){ $sg[$i]=$cs[array_rand($cs)]($sg[$i]); } } return $sg ; } return false; } } ?>
|