php - My generated salts are both exactly the same -


so, i'm 'randomly' generating 2 salts use later encryption , hashing. these generated during application's install process , copied global configurations file via:

file_put_contents() 

now, when these generated, can view them in 'globalparams.php' file. stored values of array, array not utilised @ in installation process.

the code generation follows:

// let's generate encryption salts:      $options = [     'cost' => 12,     'salt' => mcrypt_create_iv(32, mcrypt_dev_urandom),];      $salt = password_hash(mt_rand(), password_bcrypt, $options);     $salt = password_hash($salt, password_bcrypt, $options);      $salt2 = password_hash(mt_rand(), password_bcrypt, $options);     $salt2 = password_hash($salt2, password_bcrypt, $options); 

after this, placed config file so:

// let's open our template globalparams.php , replace strings..        $editfile = file_get_contents('newglobalparams.php');        $editfile = str_replace( "database_hostname", $hostname, $editfile );       $editfile = str_replace( "database_username", $dbuser, $editfile );       $editfile = str_replace( "database_password", $dbpass, $editfile );       $editfile = str_replace( "database_name", $database, $editfile );        $editfile = str_replace( "encryption_salt", $salt, $editfile );       $editfile = str_replace( "encryption_salt2", $salt2, $editfile );        // replace original globalparams.php system set up..        file_put_contents('../_includes/globalparams.php', $editfile); 

and these example outputs:

$parameters['main']['salt']   = "$2y$12$clsgeeoau5/4nez3fe8qquxwubc6al5fmcyulqtavdoiy1l7nknag"; $parameters['main']['salt2']   = "$2y$12$clsgeeoau5/4nez3fe8qquxwubc6al5fmcyulqtavdoiy1l7nknag2"; 

why identical, appended 2?

more code, including entire installer file, can posted if needed..

ta.

edit:

here results echoed right after generation:

$2y$12$uuzolwiobepd9adozrojkus3e/dushspaqkzzcdvne6bwvsydkba2 $2y$12$uuzolwiobepd9adozrojkuicthscvq2mpgtqlkngz.jluurfsdeq. 

values dumped 'globalparams.php':

$parameters['main']['salt']   = "$2y$12$uuzolwiobepd9adozrojkus3e/dushspaqkzzcdvne6bwvsydkba2"; $parameters['main']['salt2']   = "$2y$12$uuzolwiobepd9adozrojkus3e/dushspaqkzzcdvne6bwvsydkba22"; 

template of 'globalparams.php':

<?php  // global configurations file  $parameters['dbc']['hostname']  = "database_hostname"; $parameters['dbc']['username']  = "database_username"; $parameters['dbc']['password']  = "database_password"; $parameters['dbc']['database']  = "database_name";  $parameters['main']['salt']   = "encryption_salt"; $parameters['main']['salt2']   = "encryption_salt2";  session_start(); // start session, ready user login with. putenv( "tz=europe/london" ); // set timezone cookies , sessions.  require_once('databasefunctions.php'); require_once('corefunctions.php');  if(file_exists('_install/')) { // ensures no malicious user can reinstall application using own data..      exit( "please delete \"install\" directory." );  } 

the problem this:

$editfile = str_replace( "encryption_salt", $salt, $editfile ); $editfile = str_replace( "encryption_salt2", $salt2, $editfile ); 

you replacing encryption_salt in encryption_salt2 on first replacement.
second replacement nothing because pattern encryption_salt2 no longer exists.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -