LoginSignup
26
21

More than 5 years have passed since last update.

ランダムなパスワードを1行で生成する with openssl

Posted at

PHP 5.3 以上で openssl 拡張が必要。

その1

<?php
function random($n = 8)
{
    return substr(base_convert(bin2hex(openssl_random_pseudo_bytes($n)),16,36),0,$n);
}

その2

<?php
function random($n = 8)
{
    return strtr(substr(base64_encode(openssl_random_pseudo_bytes($n)),0,$n),'/+','_-');
}
26
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
21