How to generate random password with PHP?

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

Or is there a software to auto generate random passwords?

19条回答
  •  伪装坚强ぢ
    2020-12-01 01:18

    I think better way to generate random password is below function, if someone want then you can use these for strong password

    public function randPassword($upper = 2, $lower = 3, $numeric = 2, $other = 1) { 
    
            $pass_order = Array(); 
            $passWord = ''; 
    
            //Create contents of the password 
            for ($i = 0; $i < $upper; $i++) { 
                $pass_order[] = chr(rand(65, 90)); 
            } 
            for ($i = 0; $i < $lower; $i++) { 
                $pass_order[] = chr(rand(97, 122)); 
            } 
            for ($i = 0; $i < $numeric; $i++) { 
                $pass_order[] = chr(rand(48, 57)); 
            } 
            for ($i = 0; $i < $other; $i++) { 
                $pass_order[] = chr(rand(33, 47)); 
            } 
    
            //using shuffle() to shuffle the order
            shuffle($pass_order); 
    
            //Final password string 
            foreach ($pass_order as $char) { 
                $passWord .= $char; 
            } 
            return $passWord; 
        } 
    

提交回复
热议问题