Azhar Ahmad
Azhar Ahmad

Reputation: 183

Calling procedure in DbTableAuthAdapter class in zend framework2

I am using the zend framework2 and make a try to login the user using the DbTableAuthAdapter class of zend framework2 as below

 $authAdapter=new DbTableAuthAdapter($dbAdapter,'login_user','username','password','is_active=1');

but instead of this i want to call a procedure like below

 $authAdapter=new DbTableAuthAdapter($dbAdapter,'CALL `sp_user_login`(?, ?)');

Is there anyway that i call procedure instead of binding the entity?

                          OR

Anyone tell me what is wrong in my below code

   use Zend\Authentication\Adapter\DbTable as AuthAdapter;
   $hashPassword=hash("sha256", $data["password"]);
   $subQuery="select zend_with_procedure.login_user.hash_salt from   zend_with_procedure.login_user where  zend_with_procedure.login_user.username='".$data['username']."'";

   $authAdapter=new AuthAdapter($dbAdapter,'login_user','username','password','concat('.$subQuery.','.$hashPassword.') AND is_active=1');

   $authAdapter->setIdentity($data['username']);
   $authAdapter->setCredential($data['password']);
   $auth=new AuthenticationService();
   $result=$auth->authenticate($authAdapter);

I am entering the correct username and password the it shows me invalid credentials why, Does anyone have the idea ???

Upvotes: 0

Views: 110

Answers (2)

Azhar Ahmad
Azhar Ahmad

Reputation: 183

   use Zend\Authentication\Adapter\DbTable as AuthAdapter;
   $hashPassword=hash("sha256", $data["password"]);
   $subQuery="select zend_with_procedure.login_user.hash_salt from   zend_with_procedure.login_user where  zend_with_procedure.login_user.username='".$data['username']."'";

//Change this line $authAdapter=new AuthAdapter($dbAdapter,'login_user','username','password','concat('.$subQuery.','.$hashPassword.') AND is_active=1'); to $authAdapter=new AuthAdapter($dbAdapter,'login_user','username','password',"concat(".$subQuery.",?) AND is_active=1");

   $authAdapter=new AuthAdapter($dbAdapter,'login_user','username','password',"concat(".$subQuery.",?) AND is_active=1");

   $authAdapter->setIdentity($data['username']);

Change this line $authAdapter->setCredential($data['password']); to $authAdapter->setCredential($hashPassword);

   $authAdapter->setCredential($hashPassword);
   $auth=new AuthenticationService();
   $result=$auth->authenticate($authAdapter);

But not found the solution of calling a procedure!!!

Upvotes: 1

malte
malte

Reputation: 1444

I don't know which version of ZF2 you are using, but there seems to be a new CallbackCheckAdapter at least from version 2.2:

http://framework.zend.com/apidoc/2.2/classes/Zend.Authentication.Adapter.DbTable.CallbackCheckAdapter.html

Maybe using that one you can call the stored procedure?

Upvotes: 0

Related Questions