Created
March 1, 2013 18:48
-
-
Save fortunto2/5066827 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Password generate | |
* | |
* @category generate | |
* @version 0.1 | |
* @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html | |
* @param string $len длина пароля | |
* @param string $data правила генерации пароля | |
* @return string Строка с паролем | |
* @author Agel_Nash <[email protected]> | |
* | |
* Расшифровка значений $data | |
* "A": A-Z буквы | |
* "a": a-z буквы | |
* "0": цифры | |
* ".": все печатные символы | |
* | |
* @example | |
* $this->genPass(10,"Aa"); //nwlTVzFdIt | |
* $this->genPass(8,"0"); //71813728 | |
* $this->genPass(11,"A"); //VOLRTMEFAEV | |
* $this->genPass(5,"a0"); //4hqi7 | |
* $this->genPass(5,"."); //2_Vt} | |
* $this->genPass(20,"."); //AMV,>&?J)v55,(^g}Z06 | |
* $this->genPass(20,"aaa0aaa.A"); //rtvKja5xb0\KpdiRR1if | |
*/ | |
function genPass($len,$data=''){ | |
if($data==''){ | |
$data='Aa0.'; | |
} | |
$opt=strlen($data); | |
$pass=array(); | |
for($i=$len;$i>0;$i--){ | |
switch($data[rand(0,($opt-1))]){ | |
case 'A':{ | |
$tmp=rand(65,90); | |
break; | |
} | |
case 'a':{ | |
$tmp=rand(97,122); | |
break; | |
} | |
case '0':{ | |
$tmp=rand(48,57); | |
break; | |
} | |
default:{ | |
$tmp=rand(33,126); | |
} | |
} | |
$pass[]=chr($tmp); | |
} | |
$pass=implode("",$pass); | |
return $pass; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment