PHP Exercises 2013
PHP Exercises 2013
PHP Exercises 2013
Note that the PASSWORD field assumes that you are storing a hex-string representation of a
SHA-1 hash of the password. As explained in the lectures, you should never store passwords in
plaintext. There are more secure ways of storing the password. If you choose to use a different
method, the PASSWORD_HASH field of the table may no longer be CHAR(40) and you should
change it as appropriate.
Remember to properly escape user input before making the database query.
Part 3: Write the login form
Write a PHP file that will output a form containing 2 fields: username and password. Upon
submission of the form, the code should check against the database to see whether the usernamepassword pair was correct. If so, display a welcome message. If not, display the message
Invalid username or password followed by the same login form.
Once again, there should only be one PHP file, and you should redirect to the same place after
submitting. The output should be one of three options:
1. The login form.
2. The welcome message, if successful login.
3. The invalid message and the login form, if failed login.
Since we havent implemented cookies or sessions, if you successfully log in, visiting the page
again (or refreshing without resending POST data) should put you back to the login form, as if
you are not logged in. This is fine for now. We will fix this when we deal with session variables.