How to generate random password with PHP?

后端 未结 19 2226
栀梦
栀梦 2020-12-01 00:45

Or is there a software to auto generate random passwords?

19条回答
  •  悲哀的现实
    2020-12-01 01:26

    This function will generate more stronger password than most woted solution:

    function generatePassword($size=8){
        $p = openssl_random_pseudo_bytes(ceil($size*0.67), $crypto_strong);
        $p = str_replace('=', '', base64_encode($p));
        $p = strtr($p, '+/', '^*');
        return substr($p, 0, $size);      
    }
    

    Each character of password will be [A-Z] or [a-z] or ^ or *

提交回复
热议问题