Jump to content

Unexpected output in random code generation script


Recommended Posts

Dear All,

 

Below is a program that generates a random password each time the page loads, I am getting an unexpected output as "Array" on running the script:

 

<?php
    $character_set_array = array( );
    $character_set_array[ ] = array( 'count' => 5, 'characters' => 'abcdefghijklmnopqrstuvwxyz' );
    $character_set_array[ ] = array( 'count' => 1, 'characters' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' );
    $character_set_array[ ] = array( 'count' => 1, 'characters' => '0123456789' );
    $character_set_array[ ] = array( 'count' => 1, 'characters' => '!@#$+-*&?:' );
    $temp_array = array( );
    foreach ( $character_set_array as $character_set )
    {
      for ( $i = 0; $i < $character_set[ 'count' ]; $i++ )
      {
        $temp_array[ ] = $character_set[ 'characters' ][ rand( 0, strlen( $character_set[ 'characters' ] ) - 1 ) ];
      }
    }
    shuffle( $temp_array );
    implode( '', $temp_array );
    echo $temp_array;
?>

 

I am expecting output in the below format:

 

mczt0:Rm

2dwvJp!v

wo9iVk@b

c5xmx:xR

a!Xwm5qk

oyv!p8Sg

Tiu8rb&w

rmw&fa1I

 

Kindly help me out by suggesting changes/modifications/errors. Thank you.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.