Topic: Different Database for Every Company
When sharing the same database for different companies, there exists the possibility that a user of one company maliciously overwrites the data of another company. To eliminate this risk, one has to use a different database for each company.
I have eased the process this way:
in fa/admin/create_coy.php add the following code:
function rand_string( $length ) {
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$size = strlen( $chars );
for( $i = 0; $i < $length; $i++ ) {
$str .= $chars[ rand( 0, $size - 1 ) ];
}
return $str;
}
then CHANGE the following lines:
else
{
$_POST['tbpref'] = $tb_pref_counter."_";
// Insert the current settings as default
$conn = $db_connections[user_company()];
$_POST['name'] = '';
$_POST['host'] = $conn['host'];
$_POST['dbuser'] = $conn['dbuser'];
$_POST['dbpassword'] = $conn['dbpassword'];
$_POST['dbname'] = $conn['dbname'];
}
TO:
else
{
$_POST['tbpref'] = $tb_pref_counter."_";
// Insert the current settings as default
$conn = $db_connections[user_company()];
$_POST['name'] = '';
$_POST['host'] = $conn['host'];
$_POST['dbuser'] = $conn['dbuser'];
$_POST['dbpassword'] = $conn['dbpassword'];
$_POST['dbname'] = rand_string(8); //$conn['dbname'];
}
This would put a random 8 character string in the database name every time a new company is about to be created. One can always overwrite what is presented.
Can we have this included in the next release?