Last active
August 29, 2015 14:03
-
-
Save horitaku1124/d8ab37a3844ebb6e1b2d 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 | |
function makePass($length = 8) { | |
$base = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
$str = ""; | |
while($length--) { | |
$str .= $base[mt_rand(0, strlen($base) - 1)]; | |
} | |
return $str; | |
} | |
var_dump(makePass(20)); | |
$num = mt_rand(); | |
var_dump($num); | |
var_dump(base_convert($num, 10, 36)); | |
var_dump(str_replace("=", "", base64_encode($num))); | |
$bytes = openssl_random_pseudo_bytes(10); | |
var_dump(str_replace("=", "", base64_encode($bytes))); | |
var_dump(bin2hex($bytes)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参考サイト
http://qiita.com/suin/items/c958bcca90262467f2c0