User Login and Registration

After looking over the requirements for user login and registration, you can work on implementing those requirements in two stages:

Login/Registration Requirements

The requirements for the login and registration are described by screen shots along with a description of behavior.

Login

The login page should be the first page that users see in the modified application. It should provide two text fields - one for entering a login name and one for entering a password. In addition it should have a command button that initiates the password checking action. If either of the text fields is left blank it is an error that must be reported to the user. If both fields are filled in but there is no record of the user name or the password is incorrect that must also be reported to the user.

Users that have not yet registered cannot log in. They must first register by clicking on the register command button. They should be able to do this without getting an error for an empty name or password field.

Login - Missing Fields

When the login command button is clicked without filling in the name field or without filling in the password field the user should see error messages similar to those above.

Incorrect Login

When the login command button is clicked after filling in the name field password fields but the name is unknown or the password is incorrect the user should see an error message similar to the one above.

Even when the user has filled in both fields the password field should be blank after an incorrect login (the getter for the password property always returns an empty string). The implementation shown above handled the name property the same way, but a friendlier implementation would show the login name as it was entered before clicking the login command button. Then the user would not have to enter it again unless they saw that it was incorrect.

Registration

The registration page should be displayed when a user clicks on the register command button in the login page. It should provide three text fields - one for entering a login name and two for entering passwords. In addition it should have a command button that initiates the registration action.

If any of the text fields is left blank it is an error that must be reported to the user. If all fields are filled in but there is already a record for the user name then that must be reported as an error. If the two passwords are different that must also be reported as an error.

Registration - Missing Fields

When the register command button is clicked without filling in the name field or without filling in both password fields the user should see error messages similar to those above. Both passwords field should be blank after this error but the login name may be visible.

Registration - Name Taken

When the user attempts to register with a login name that is already taken the user should see an error message similar to the one above.

Web Page Reorganization

You should start by reorganizing the web pages. Rename your index.xhtml page to select-category.xhtml or some other name that reflects its purpose of selecting a category. Then you will need to create a new index.xhtml, which is a login page, and another page for registration.

For now, you can use static navigation in your login and registration pages. The navigation from the login page "Register" button should be to the registration page. The navigation from other command buttons should be to your category selection page.

You should implement and check handling for missing input data in either the login or registration page at this time.

The User Bean

You will need a user bean to deal with user login and later score recording. It should implement action methods for the login and registration page command buttons. It should be session scoped.

You will also need some new methods in the Database class to support the user bean.

Database Class Support

To support registration and login, the Database class needs a new instance variable for user passwords, a method for getting the password for a username and a method for adding a password for a new user. The instance variable should have type Map<String, String>. That should be enough of a hint to complete the method implementations.

Recall that you will need to inject the Database bean into the User in order to access it.