Dreamweaver : Create a Login page and Userdetails table

July 10, 2006

This Tutorial walks you through setting up a database table to house your Users login details, and set up a Login page within Dreamweaver.

It also included details on Restricting access to pages within your site to only those who have logged in via your Login page.

Prerequisites

You will need either PWS or IIS running on your computer to run the ASP pages.

This Tutorial expects some experience in developing ASP pages in Dreamweaver MX, although each part will be walked through point by point, so you really just need to feel comfortable using Dreamweaver MX (trial version can be downloaded from macromedia.com)

You will need to know how to create a datebase and add tables.

Details

  1. Create a new database in your choice of flavour (Access, SQL Server, MySQL)
  2. Create a new table, name it user_logins
  3. Change to design view.
  4. Create a column for AccountID, UserName, UserPassword and any others you may wish, i.e UserReal, UserEmail etc, CreatedDate but the first 3 are a minimum

Types for each column

  • AccountID (Access= Autonumber, SQL server = int, Identity, not for repeating)<–primary key
  • UserName (Access=text, SQL server = varchar (50) )
  • UserPassword (Access=text, SQL server = varchar (50) )
  • If using Created Date (Access=date, default = now() SQL server=Date/time, default=getdate() )

Save your table

Open Dreamweaver

  • Create a new ASP page.
  • Add a form tag (call it something like fmlogin)
  • Add 2 text fields, call 1=Username, 2=Userpassword
  • Add a Submit button
  • In the Application palette…Server Behaviours…Authenticate User…Login user
  • Choose your connection (this will need setting up before hand to either talk to an ODBC or DSN-less connection)
  • Select the user_logins table.
  • Dreamweaver would have already entered the Form fields for Username and Password, you will need to tell it which columns in the database are for Username and Password.
  • Enter the page you wish it to go to if the login is successful, and the one if the login fails.

You have finished your login page.

If you only want people who have logged in to see them, you will need to restrict each page you are protecting with this login.

Open each page you want to protect …. In the Application pallete…Server Behaviours…Authenticate User…Restrict access to page.

Enter the page to go to if someone tries to access the page without logging in, or if their session has timed out.


Dreamweaver : Dynamically redirect your Login page

July 10, 2006

This Tutorial enables you to use 1 login page for sites with areas restricted to certain users.

By using a column in your database, and a small piece of coding to add to the login script, you can move your users dynamically to the appropriate folder for their access level.

Prerequisites

You need to be comfortable using Dreamweaver MX, and be able to follow basic instructions in adding code to the prebuilt dreamweaver page.

You will need a database, either Access or SQL server and be comfortable designing the database and tables required.

Details

Create a table in your database with a minimum of 4 fields,

ID for the record, Username, UserPassword and AccessLevel

Create your login page as normal;

  • design your page
  • add a form and enter two field box for the Username and Password.

In Application/Server behaviours/User Authentication select Login user.
Set the behaviour up by choosing the correct connection, table and marrying up the form fields to the database fields.

Enter your failed and successful pages as normal, and make sure you select to use Access Level as well as Username and Password. Use the column AccessLevel in the database for the Access level.

Save your page.

Change to Code view.

Your login code will be at the top of the page, move down the code until you find:

If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then ‘ username and password match – this is a valid user

Move down a little until this line Session(“MM_UserAuthorization”) = “” End If

Enter a break return and paste this code below that line:

‘ redirect user based on Access level
If Session(“MM_UserAuthorization”) = “category1″ Then
MM_redirectLoginSuccess = “folder1/”
ElseIf Session(“MM_UserAuthorization”) = “category2″ Then
MM_redirectLoginSuccess = “folder2/”
Else MM_redirectLoginSuccess = “folder3/”
End If

Change the category1, category2 to the settings you have in the column AccessLevel in your user details table.

Change the folder for folder1, folder2 to respective folders for each category.

The final folder3 is for the default folder or file to move to if the person exists in the table, but a Access Level has not been found.

If you always require an Access Level to be found, then set this last If to the failed page. You can add more ElseIf statements for extra categories.

Don’t forget to use the Restrict Access to page behaviour on each page that requires a login, so if for someone does get by, they will automatically be moved to your failed page, and not gain access simply by entering a URL.