Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Generate a random and unique password

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 105
    Comment on it

    Hello readers, today we discuss about "Generate a random, unique password or alphanumeric string" using Php function.

    function random_string($len) {
        $key = '';
        $keys = array_merge(range(0, 9));
    
        for ($i = 0; $i < $len; $i++) {
            $key .= $keys[array_rand($keys)];
        }
    
        return $key;
    }
    
    echo random_string(4);
    

    In above code the password should be only come in integer and the length is 4 digit.

    If you want alphanumeric string and the output length more than 4 so you can use the below code.

      function random_string($len) {
            $key = '';
            $keys = array_merge(range(0, 9), range('a', 'z'));
    
            for ($i = 0; $i < $len; $i++) {
                $key .= $keys[array_rand($keys)];
            }
    
            return $key;
        }
    
        echo random_string(10);
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: