Login using Javascript Code

A simple login using javascript code

Page 1 of 1

6 Replies - 71027 Views - Last Post: 24 June 2008 - 11:03 AM

#1 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Login using Javascript Code

Post icon  Posted 23 June 2008 - 03:24 PM

NOTE: If you want the final script instead of copy / paste just download the attatchment and change the file extension from .txt to .js

First change the u1, u2, etc to the usernames that you wish. Do the same for the p1, p2, etc. NOTE:there is NO limit on the usernames & passwords. Next change the yourpage.html to whatever page you want.

<!-- Begin

function Login(form)
{
username = new Array("u1","u2","u3","u4","u5","u6","u7","u8","u9","u10");
password = new Array("p1","p2","p3","p4","p5","p6","p7","p8","p9","p10");
page = "yourpage" + ".html";
if (form.username.value == username[0] && form.password.value == password[0] || form.username.value == username[1] && form.password.value == password[1] || form.username.value == username[2] && form.password.value == password[2] || form.username.value == username[3] && form.password.value == password[3] || form.username.value == username[4] && form.password.value == password[4] || form.username.value == username[5] && form.password.value == password[5] || form.username.value == username[6] && form.password.value == password[6] || form.username.value == username[7] && form.password.value == password[7] || form.username.value == username[8] && form.password.value == password[8] || form.username.value == username[9] && form.password.value == password[9])
{
	window.self.location.href = page;
	return true;
}
else
{
	alert("Either the username or password you entered is incorrect.\nPlease try again.");
	form.username.focus();
}
return true;
}

// End -->




to use this script on a html page insert this right before the form tag

<script language="Javascript" type="text/Javascript" src="login.js"></script>



Tell me what you think by rating / comments.

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Login using Javascript Code

#2 MRJ  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 118
  • Joined: 13-October 07

Re: Login using Javascript Code

Posted 23 June 2008 - 03:39 PM

Looks functional, but it's not very good security. Javascript is viewable in the browser so anyone viewing the source of your site would see the usernames and passwords.
Was This Post Helpful? 0
  • +
  • -

#3 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Re: Login using Javascript Code

Posted 23 June 2008 - 03:47 PM

View PostMRJ, on 23 Jun, 2008 - 03:39 PM, said:

Looks functional, but it's not very good security. Javascript is viewable in the browser so anyone viewing the source of your site would see the usernames and passwords.



yeah i know but it works for a non-major site.
Was This Post Helpful? 0
  • +
  • -

#4 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Login using Javascript Code

Posted 24 June 2008 - 02:57 AM

You are only cheating yourself if you use something like this.
It is not about the size of the site, but the technical knowledge of the users. However if it has anything worth putting a user name and password on the site, chances are pretty great that a user will ask somebody with the most basic HTML/Javascript knowledge to check to site for him, and at that point it is over.
Was This Post Helpful? 0
  • +
  • -

#5 idlepoze  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 6
  • Joined: 23-June 08

Re: Login using Javascript Code

Posted 24 June 2008 - 06:38 AM

View Post1lacca, on 24 Jun, 2008 - 02:57 AM, said:

You are only cheating yourself if you use something like this.
It is not about the size of the site, but the technical knowledge of the users. However if it has anything worth putting a user name and password on the site, chances are pretty great that a user will ask somebody with the most basic HTML/Javascript knowledge to check to site for him, and at that point it is over.



Totally agree with 1lacca, try using PHP/ASP or even better .htaccess for secure login.
Was This Post Helpful? 0
  • +
  • -

#6 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Re: Login using Javascript Code

Posted 24 June 2008 - 10:16 AM

I know it isn't very secure but it works for practicing your javascript code which helps with web design

View Postidlepoze, on 24 Jun, 2008 - 06:38 AM, said:

View Post1lacca, on 24 Jun, 2008 - 02:57 AM, said:

You are only cheating yourself if you use something like this.
It is not about the size of the site, but the technical knowledge of the users. However if it has anything worth putting a user name and password on the site, chances are pretty great that a user will ask somebody with the most basic HTML/Javascript knowledge to check to site for him, and at that point it is over.



Totally agree with 1lacca, try using PHP/ASP or even better .htaccess for secure login.

Was This Post Helpful? 0
  • +
  • -

#7 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Login using Javascript Code

Posted 24 June 2008 - 11:03 AM

I appreciate your willingness to help others. We have a tutorial and a snippet section for submitting such entries. In the forums we discuss problems and help finding errors in the code.
So if you've posted your snippet with educational purpose, I'd like to ask you to revise it, because the way you check the password is a typical anti pattern ("ugly") if (form.username.value == username[0] && form.password.value == password[0] || form.username.value == username[1] && form.password.value == password[1] || form.username.value == username[2] && form.password.value == password[2] || form.username.value == username[3] && form.password.value == password[3] || form.username.value == username[4] && form.password.value == password[4] || form.username.value == username[5] && form.password.value == password[5] || form.username.value == username[6] && form.password.value == password[6] || form.username.value == username[7] && form.password.value == password[7] || form.username.value == username[8] && form.password.value == password[8] || form.username.value == username[9] && form.password.value == password[9])
{

I'd suggest using a loop for this.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1