Skip to content

Instantly share code, notes, and snippets.

@horitaku1124
Last active August 29, 2015 14:03
Show Gist options
  • Save horitaku1124/d8ab37a3844ebb6e1b2d to your computer and use it in GitHub Desktop.
Save horitaku1124/d8ab37a3844ebb6e1b2d to your computer and use it in GitHub Desktop.
パスワードもどきを簡単に生成
<?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));
@horitaku1124
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment