[QUOTE=nacyil;31166]Hello Dave
There is something strange anywhere, when I change the database user validation is incorrect :
$arr_conn['database'] = trim($mdbname);
sc_connection_edit("conn_mysql", $arr_conn);
sc_change_connection("system","conn_mysql");
$slogin = sc_sql_injection({login});
$spswd = sc_sql_injection(md5({pswd}));
$sql = "SELECT priv_admin,active, name, email,themes_name FROM sec_users WHERE login = $slogin AND pswd = ".$spswd."";
sc_lookup(rs, $sql);
The problem is :
I connect with my login and pwd in 1st database, I quit and connect to an another database but with same login and pwd (this user does not exist in 2nd db) but its accepted.
I quit and try to connect again to 2nd db always with same login and pwd , at this point it doesn’t find this user ???
Hope my explanation is clear enough !!!
Nac[/QUOTE]
Nac,
At first glance, the problem that you are having should be fixed if you change sc_lookup(rs, $sql) to sc_lookup(rs, $sql, “system”) however it would appear to me that you are planning multiple databases each with its own users file. I would not do it that way.
In my environment, I use a single database for all user logins, and multiple (~75) identically structured databases for the remainder of the system. This is so that I can store the database connection information in the user’s login record.
I use “system” as the default database connection for the login app, and “account” as the default database connection for the remainder of the apps. When I read the users table from the login app, I load the database connection info from the users’s table.
I code it like this:
$slogin = sc_sql_injection({login});
$spswd = sc_sql_injection(md5({pswd}));
$sql = "SELECT db_server,db_name,db_user,db_password,priv_admin,active, name, email,themes_name FROM sec_users WHERE login = $slogin AND pswd = ".$spswd."";
sc_lookup(rs, $sql, "system");
// Check for errors here of course...
$arr_conn['server'] = $rs[0];
$arr_conn['database'] = $rs[1];
$arr_conn['user'] = $rs[2];
$arr_conn['password'] = $rs[3];
sc_connection_edit("account", $arr_conn);
// Since all the rest of the applications use "account" as their default connection, the user is now using the proper database
// We have not messed with "system", so that can still be used as default for the apps that add/edit users, and things like that.
This, of course, requires that you have already manually created connections called “system” and “account”, and that the default connection for login app is “system” and all the applications after the login app have default connection “account”. (This is not strictly true, because I have apps to add and edit users, etc., that also use the “system” connection).
Slightly different topic:
If you want to programmatically access a database in the same application where you are changing the database, then you need to do things a bit differently:
// We are going to use a connection called "special".
// Whatever connection you choose:
// 1. CANNOT be the default connector for this application.
// 2. Must have a connection by this name already existing.
// Notice below the name of the array in the Ini object is "nm_con_special" because our connector is named "special"
// If your connector is named differently, then change the array name.
$this->Ini->nm_con_special['servidor'] = $server;
$this->Ini->nm_con_special['banco'] = trim($mdbname);
$this->Ini->nm_con_special['usuario'] = $user;
$this->Ini->nm_con_special['senha'] = encode_string_utf8($password);
$this->Ini->conectExtra();
$sql = "SELECT [something] FROM [table] WHERE [condition]";
sc_lookup(rs, $sql, "special"); // You MUST specify the connector here!!
Also, please note that this will all change if/when NetMake gets around to fixing the bug.
Dave