BW Network
    Login | Register 

3 visitors online
Guests: 3
Registered: 0

SafeSurf Logo

Website BuildingTutorials → Javascript: Login Script (Part 5)

You can use this script on your own site and modify it as you wish!

<TITLE>Password script
//Passcheck script -
function passcheck() {
//Set login success to bad to prevent refreshes of page affecting login
//Define the username and password variables
username = document.entranceform.username.value.toLowerCase();
password = document.entranceform.password.value.toLowerCase();
//Check each username and password in turn
if (username=="benjamin" && password=="password1") {
if (username=="john" && password=="letmein") {
if (username == "matthew" && password=="iamdumb") {
//Sends them to pagepassed.html if successful
if (document.entranceform.login.value == "good") {
//Gives them an error message if login is incorrect
if (document.entranceform.login.value != "good")
alert("Incorrect username and/or password");
<form name="entranceform" onSubmit="passcheck()">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="Submit!">
<input type="hidden" name="login">

The above script first defines a function. It then creates two variables, username and password and makes them lowercase to prevent capitals making a problem. It then checks the username to see if there is a matching password and if yes defines what happens (in this case moving to page 'pagepassed.html').

Congratulations on completing our tutorial, please check out the below links if you would like to learn more on Javascript!

  1. Introduction
  2. Part 1: Further Introduction
  3. Part 2: Basic Implementation
  4. Part 3: Strings & Variables
  5. Part 4: Forms
  6. Part 5: Login Script