# How to solve deprecated "DbTableAuthAdapter" ocurred in LoginController of my studying "old book ZF2.0 by example" by utilizing ZF 2(ver 2.4.9, PHP 7.1)

**URL:** <https://discourse.laminas.dev/t/how-to-solve-deprecated-dbtableauthadapter-ocurred-in-logincontroller-of-my-studying-old-book-zf2-0-by-example-by-utilizing-zf-2-ver-2-4-9-php-7-1/930>\
**Category:** Components & MVC\
**Tags:** authentication\
**Created:** [February 3, 2019, 3:35am UTC](https://discourse.laminas.dev/t/how-to-solve-deprecated-dbtableauthadapter-ocurred-in-logincontroller-of-my-studying-old-book-zf2-0-by-example-by-utilizing-zf-2-ver-2-4-9-php-7-1/930 "2019-02-03T03:35:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhushaolei](https://avatars.discourse-cdn.com/v4/letter/z/b19c9b/32.png) [@zhushaolei](https://discourse.laminas.dev/u/zhushaolei)\
**Post date:** [February 3, 2019, 3:35am UTC](https://discourse.laminas.dev/t/how-to-solve-deprecated-dbtableauthadapter-ocurred-in-logincontroller-of-my-studying-old-book-zf2-0-by-example-by-utilizing-zf-2-ver-2-4-9-php-7-1/930/1 "2019-02-03T03:35:29Z")

</div>

\<?php namespace Users\Controller; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; use Zend\Authentication\AuthenticationService; use Zend\Authentication\Adapter\DbTable as DbTableAuthAdapter; use Users\Form\LoginForm; use Users\Form\LoginFilter; use Users\Model\User; use Users\Model\UserTable; class LoginController extends AbstractActionController { protected $storage; protected $authservice; public function getAuthService() { if (! $this-\>authservice) { $this-\>authservice = $this-\>getServiceLocator()-\>get('AuthService'); } return $this-\>authservice; } public function logoutAction() { $this-\>getAuthService()-\>clearIdentity(); return $this-\>redirect()-\>toRoute('users/login'); } public function indexAction() { $form = $this-\>getServiceLocator()-\>get('LoginForm'); $viewModel = new ViewModel(array('form' =\> $form)); return $viewModel; } public function processAction() { if (!$this-\>request-\>isPost()) { return $this-\>redirect()-\>toRoute('users/login'); } $post = $this-\>request-\>getPost(); $form = $this-\>getServiceLocator()-\>get('LoginForm'); $userTable = $this-\>getServiceLocator()-\>get('UserTable'); $form-\>setData($post); if (!$form-\>isValid()) { $model = new ViewModel(array( 'error' =\> true, 'form' =\> $form, )); $model-\>setTemplate('users/login/index'); return $model; } else { //check authentication... $this-\>getAuthService()-\>getAdapter() -\>setIdentity($this-\>request-\>getPost('email')) -\>setCredential($this-\>request-\>getPost('password')); $result = $this-\>getAuthService()-\>authenticate(); if ($result-\>isValid()) { $this-\>getAuthService()-\>getStorage()-\>write($this-\>request-\>getPost('email')); return $this-\>redirect()-\>toRoute('users/login', array( 'action' =\> 'confirm' )); } else { $model = new ViewModel(array( 'error' =\> true, 'form' =\> $form, )); $model-\>setTemplate('users/login/index'); return $model; } } } public function confirmAction() { $this-\>layout('layout/myaccount'); $user\_email = $this-\>getAuthService()-\>getStorage()-\>read(); $viewModel = new ViewModel(array( 'user\_email' =\> $user\_email )); return $viewModel; } } --- \*\*my some of snipplet codes of module.php is:\*\* public function getServiceConfig() { return array( 'abstract\_factories' =\> array(), 'aliases' =\> array(), 'factories' =\> array( // SERVICES 'AuthService' =\> function($sm) { $dbAdapter = $sm-\>get('Zend\Db\Adapter\Adapter'); $dbTableAuthAdapter = new DbTableAuthAdapter($dbAdapter, 'user','email','password', 'MD5(?)'); $authService = new AuthenticationService(); $authService-\>setAdapter($dbTableAuthAdapter); return $authService; }, // DB 'UserTable' =\> function($sm) { $tableGateway = $sm-\>get('UserTableGateway'); $table = new UserTable($tableGateway); return $table; }, 'UserTableGateway' =\> function ($sm) { $dbAdapter = $sm-\>get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype-\>setArrayObjectPrototype(new User()); return new TableGateway('user', $dbAdapter, null, $resultSetPrototype); },

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [February 3, 2019, 8:00am UTC](https://discourse.laminas.dev/t/how-to-solve-deprecated-dbtableauthadapter-ocurred-in-logincontroller-of-my-studying-old-book-zf2-0-by-example-by-utilizing-zf-2-ver-2-4-9-php-7-1/930/2 "2019-02-03T08:00:18Z")

</div>

Please format your code example otherwise nobody can help. You can do this by adding 3 backticks (grave accent) before and after the code.

**Example:**

```php  
class Foo  
{  
public const BAR = true;  
}  
```

(the example code includes whitespace)

**Produces:**

```php
class Foo
{
    public const BAR = true;
}

```

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [February 3, 2019, 8:02am UTC](https://discourse.laminas.dev/t/how-to-solve-deprecated-dbtableauthadapter-ocurred-in-logincontroller-of-my-studying-old-book-zf2-0-by-example-by-utilizing-zf-2-ver-2-4-9-php-7-1/930/3 "2019-02-03T08:02:57Z")

</div>

I have already given you an answer in the bugtracker and where you can find the solution:

> Please look at the documentation of zend-authentication. There you will find the notification of the deprecation and the also how you can fix the problem: [Intro - zend-authentication - Zend Framework Docs](https://docs.zendframework.com/zend-authentication/adapter/dbtable/intro/#zendauthenticationadapterdbtable-class-is-deprecated)

> <https://github.com/zendframework/zend-db/issues/352#issuecomment-456284222>
>
> \- \[x\] I was not able to find a solution to the \`DbTableAuthAdapte\` deprecated:… 
> in follwoing snippet:
> 
> \`\`\`php
> public function getServiceConfig()
> {
> return array(
> 'abstract\_factories' =\> array(),
> 'aliases' =\> array(),
> 'factories' =\> array(
> // SERVICES
> 'AuthService' =\> function($sm) {
> $dbAdapter = $sm-\>get('Zend\\Db\\Adapter\\Adapter');
> $dbTableAuthAdapter = new DbTableAuthAdapter($dbAdapter, 'user','email','password', 'MD5(?)');
>                 
> $authService = new AuthenticationService();
> $authService-\>setAdapter($dbTableAuthAdapter);
> return $authService;
> },
> \`\`\`
> 
> Provide a narrative description of what you are trying to accomplish.
> I wish to get a correct solution ( a snippet code) against to \`DbTableAuthAdapter\` to fix my login functionality and continue to study and practise on the book" Zend Framework2.0 by example"
