• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Lesson 14. Restricting Access > Building a Functioning Log-In Page

Building a Functioning Log-In Page

In this task, you will create the log-in page so registered users can access restricted pages. This page has a form on it, which is processed by a server behavior. This time, instead of using the Insert Record server behavior, you'll use the Log In User server behavior.

Open login.cfm. Switch to Code View, scroll down near the bottom of the page, and enclose the table inside <form> tags as you did in the previous lesson (add the tags in lines 49 and 61).

Usually, you can add forms in Design View—you don't have to do it in Code View. In both this page and index.cfm from the previous task, though, I have already built a table, and it is hard to add a form around a table in Design View. Sometimes, when you need to be precise, it is easier just to switch into Code View and type in the code directly.

Switch back to Design View, and using the Forms tab of the Insert panel, insert two text fields and a Submit button. Play with the formatting until they line up with the labels on the left side.

The log-in form needs only two fields—a username and a password. The other fields would be redundant, since they are already in the database.

In turn, select each of the text fields, and in the Property inspector, change their names to username and password. For the password field, make sure you select the Password option in the Property inspector. Then select the <form> tag in the tag selector, and name it login.

No matter how short the form, always name each of the fields and the form itself.

The form is now complete.

Click to select the Submit button, and then click the + button in the Server Behaviors panel to open the list of behaviors, and choose User Authentication > Log In User.

As with the other server behaviors you have added, this one's dialog sometimes takes a moment to appear. That's because Dreamweaver is accessing your data source list as it prepares to populate the dialog with your database's field names.

Verify that the first three fields specify login in the Get Input From Form field, username in the Username Field, and password in the Password field.

Again, you can make Dreamweaver work for you by naming fields descriptively. When you do so, the software will correctly match fields to names and you'll avoid some extra typing.

Choose elearning from the Validate Using Data Source drop-down menu. Wait for it to load the data, and choose users from the Table drop-down menu, username from the Username Column menu, and password from the Password Column menu.

In this step, you are telling ColdFusion how to map the HTML form fields to those in the database.

In the If Login Succeeds, Go To field, type or browse to welcome.cfm. In the If Login Fails, Go To field, type or browse to login_failed.cfm. Leave the Go To Previous URL checkbox unchecked. Leave Restrict Access Based On at the default, Username and Password. Click OK.

In this step, you are specifying the branching behavior the application should make based on whether the user's credentials were valid.

The Restrict Access Based On option at the bottom, by the way, enables you to create pages with different levels of access.

Because this page automatically rejects any values that don't match those in the database, you don't have to worry about form validation. If a user doesn't enter both a username and a password, she or he will be sent automatically to the login_failed.cfm page.

Save the file. If you like, test it by entering the username and password you created in the previous lesson.

If you test the page, you will see that entering a correct set of credentials takes you to welcome.cfm, while entering incorrect credentials takes you to login_failed.cfm.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint