Can we add Schema for table_name in a CredentialTreatmentAdapter for authentification?

Hello,

I work to a migration of an old app who running with ZF1 and I have a problem for authentification with authentification with a CredentialTreatmentAdapter.
In fact my table where’s I have my ID and password is in a schema, and that make bug my authenticate.

Here my code, the name of my table is “vw_identification” and this table is in the schema “mps”, and that don’t found my table. This code work if I delete “mps” but that don’t go to the good schema unfortunally.

$authAdapter = new CredentialTreatmentAdapter($adapter);

$authAdapter
    ->setTableName('mps.vw_identification')
    ->setIdentityColumn('identifiant')
    ->setCredentialColumn('motdepasse')
    ->setCredentialTreatment('?');


$authAdapter->setIdentity('my_username')
    ->setCredential(md5("my_password"));

$result = $authAdapter->authenticate();

My question is theres is a way to specify Schema_name on a credentialTreatmentAdapter ? Or something to make that work ?

My Database is postgres for information ( I’m not sure this is useful)

Sorry for my bad english, this not my native langage and I’m not really good in english.

And big thanks for your help.

Dear @Dautheville.dylan,

It is a sacrilege to use MD5 in 2022. Someone will demote you on this same line. It doesn’t matter what you say in the board meeting you’ll be the victim. I hope you didn’t take it personally because it is a joke. Back to the question now, the simple answer is no. You’ve to pass a new adapter or a secondary adapter to CredentialTreatmentAdapter. Because the adapter contains schema information. I hope I’ve answered your question. Thanks!

Dear @ALTAMASH80 ,
Thanks for your answer.
For md5 it’s an old application :').
How can I change the schema in the Db Adapter? I don’t see any such information in the constructor and if I change the database field to “myDatabase.Schema” it doesn’t work. There’s is a way to do that ?

$adapter = new Adapter([
    'driver'   => 'pdo_pgsql',
    'database' => 'myDatabase.mySchema',
    'username' => 'MyUserDB',
    'password' => '123',
    'hostname' => 'localhost',
    'port' => '5434'
]);

Thanks!

Dear @Dautheville.dylan,

The way to handle adapters is to create multiple adapters. But schema is referred to the database name itself. How you can use it in MVC there is an old post of mine which shows that ZfcUser aka LmcUser has this functionality built in but in a different way. You can view the post here if you’ve ever used LmcUser. Thanks!

$adapter = new Adapter([
    'driver'   => 'pdo_pgsql',
    'database' => 'myDatabase.mySchema1',
    'username' => 'MyUserDB',
    'password' => '123',
    'hostname' => 'localhost',
    'port' => '5434'
]);

$adapter2 = new Adapter([
    'driver'   => 'pdo_pgsql',
    'database' => 'myDatabase.mySchema2',
    'username' => 'MyUserDB',
    'password' => '123',
    'hostname' => 'localhost',
    'port' => '5434'
]);

Dear @ALTAMASH80 ,
Thanks for your answer but when I try to connect my DB with MyDatabase.mySchema1 I juste get an error about my Database not exists.


Thanks!

Hi @Dautheville.dylan,

I’ve used the names which you’ve used in your configuration and just added a postfix “1” and “2”. But I’ve never used configuration like yours and have not yet seen it. Database and Schema refer to one thing: the database itself. So, I’ll only suggest to keep playing with the configuration. Either by removing “Mydatabase.” or “.schema” from the configuration. Or check the name of the database in your MySQL server or MySqlYog and use that name. Thanks!