Welcome to Dream.In.Code
Getting Help is Easy!

Join 109,297 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,221 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Login using Javascript Code

 
Reply to this topicStart new topic

Login using Javascript Code, A simple login using javascript code

gbertoli3
post 23 Jun, 2008 - 03:24 PM
Post #1


DIC at Heart + Code

Group Icon
Joined: 23 Jun, 2008
Posts: 666



Thanked 7 times

Dream Kudos: 625
My Contributions


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.

CODE

<!-- 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

CODE

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


Tell me what you think by rating / comments.


Attached File(s)
Attached File  loginScript.txt ( 1.17k ) Number of downloads: 46
User is offlineProfile CardPM

Go to the top of the page


MRJ
post 23 Jun, 2008 - 03:39 PM
Post #2


D.I.C Head

Group Icon
Joined: 13 Oct, 2007
Posts: 82


My Contributions


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.

User is offlineProfile CardPM

Go to the top of the page

gbertoli3
post 23 Jun, 2008 - 03:47 PM
Post #3


DIC at Heart + Code

Group Icon
Joined: 23 Jun, 2008
Posts: 666



Thanked 7 times

Dream Kudos: 625
My Contributions


QUOTE(MRJ @ 23 Jun, 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.



yeah i know but it works for a non-major site.
User is offlineProfile CardPM

Go to the top of the page

1lacca
post 24 Jun, 2008 - 02:57 AM
Post #4


code.rascal

Group Icon
Joined: 11 Aug, 2005
Posts: 3,721



Thanked 9 times
My Contributions


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.
User is offlineProfile CardPM

Go to the top of the page

idlepoze
post 24 Jun, 2008 - 06:38 AM
Post #5


New D.I.C Head

*
Joined: 23 Jun, 2008
Posts: 4

QUOTE(1lacca @ 24 Jun, 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.



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

Go to the top of the page

gbertoli3
post 24 Jun, 2008 - 10:16 AM
Post #6


DIC at Heart + Code

Group Icon
Joined: 23 Jun, 2008
Posts: 666



Thanked 7 times

Dream Kudos: 625
My Contributions


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

QUOTE(idlepoze @ 24 Jun, 2008 - 06:38 AM) *

QUOTE(1lacca @ 24 Jun, 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.



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

User is offlineProfile CardPM

Go to the top of the page

1lacca
post 24 Jun, 2008 - 11:03 AM
Post #7


code.rascal

Group Icon
Joined: 11 Aug, 2005
Posts: 3,721



Thanked 9 times
My Contributions


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.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 9/6/08 09:45AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month