Created
March 26, 2013 12:29
-
-
Save akira345/5245011 to your computer and use it in GitHub Desktop.
PHPでのランダムパスワード生成プログラムを書いてみた。
This file contains 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 | |
class DefaultPassword { | |
public function generate(){ | |
//乱数初期化 | |
srand(); | |
//12文字以上16文字未満 | |
$in_length = rand(12,16); | |
//アルファベット | |
for($i=0;$i<25;++$i){ | |
$seed_alpha[$i] = chr(65+$i); | |
} | |
//記号 | |
$seed_char = array("!","\"","#","$","%","&","'","(",")"); | |
for($i=0;$i<$in_length;++$i){ | |
switch ($i%4){ | |
case 0: | |
//アルファベット大文字 | |
$passwd .= $seed_alpha[rand(0,count($seed_alpha)-1)]; | |
break; | |
case 1: | |
//アルファベット小文字 | |
$passwd .= strtolower($seed_alpha[rand(0,count($seed_alpha)-1)]); | |
break; | |
case 2: | |
//数字 | |
$passwd .= rand(0,9); | |
break; | |
default: | |
//記号 | |
$passwd .= $seed_char[rand(0,count($seed_char)-1)]; | |
break; | |
} | |
} | |
return $passwd; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment