How to implement user login in Zend Framework 2?

I am trying to implement a very simple Zend login form; however I am having trouble understanding how this works.

I have an HTML form with fields username

, password

and submit

. I don't know how to check the username and password.

How can I do this without using Zend Form?

+3


source to share


2 answers


When the browser submits the completed form to the server, you can get the posted values ​​with your controller like this:

$username = $this->params()->fromPost('username');
$password = $this->params()->fromPost('password');

      

Then you need to pass these values ​​to whatever authentication mechanism you want to use. For example, you can do a simple database search with your custom table.



However, life is not easy. You need to think about security. Validation and filtering of values ​​submitted from the form, hashing passwords, etc.

You also need to think about how to handle the invalid login, such as re-rendering the form with an additional display explaining the failure. Zend \ Form can help you with some of these problems.

+3


source


I would start looking at the zfcUser module, which can be found here:



https://github.com/ZF-Commons/ZfcUser

+1


source







All Articles