Logging in and authentication
We are going to simplify things. We simply match the email and password combination received from the form to what we have on the admins table to verify the user’s identity. Since the saved password is encrypted, we also have to encrypt the raw password received from the form before comparing them.
Edit source\empcontrol.d and add this method.
We used the enforce() function before. The enforce() function is a built-in D function that does nothing if the first parameter is true, and aborts and returns the error message if is false.
Edit source\empmodel.d and add this method.
Compile, run and refresh the browser, then try to log in with a random, non-existent admin first and click on the Login button. The index page with an error message should be shown.
Then click on the Login link again and input an existing admin and try to login (remember, ‘secret’ is the password).
If the list of employees is shown, you did good.
Now let’s talk about saving the login state. Let's talk about the session.
Last updated