public static function generateRandomPassword($length = 8, $customAlphabet = null)
    {
        $pass = [];
        if (strlen(trim($customAlphabet))) {
            $alphabet = trim($customAlphabet);
        } else {
            $alphabet = 'abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789';
        }

        $alphaLength = strlen($alphabet) - 1;
        for ($i = 0; $i < $length; $i++) {
            $n = rand(0, $alphaLength);
            $pass[] = $alphabet[$n];
        }

        return implode($pass);
    }
public static function generateRandomPassword($length = 8, $customAlphabet = null)
    {
        $pass = [];
        if (strlen(trim($customAlphabet))) {
            $alphabet = trim($customAlphabet);
        } else {
            $alphabet = 'abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789';
        }

        $alphaLength = strlen($alphabet) - 1;
        for ($i = 0; $i < $length; $i++) {
            $n = rand(0, $alphaLength);
            $pass[] = $alphabet[$n];
        }

        return implode($pass);
    }
public static function generateRandomPassword ( $ length = 8 , $ customAlphabet = null ) { $ pass = [ ] ; if ( strlen ( trim ( $ customAlphabet ) ) ) { $ alphabet = trim ( $ customAlphabet ) ; } else { $ alphabet = 'abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789' ; } $ alphaLength = strlen ( $ alphabet ) - 1 ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ n = rand ( 0 , $ alphaLength ) ; $ pass [ ] = $ alphabet [ $ n ] ; } return implode ( $ pass ) ; }
Generate Simple Random Password.

@param int    $length         length of generated password, default 8
@param string $customAlphabet a custom alphabet string

@return string Generated Password
Generate Simple Random Password .