Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 06-13-2006, 08:47 AM   #1 (permalink)
markster
Code Monkey
 
markster's Avatar
 
Join Date: Jun 2006
Posts: 65
markster is on a distinguished road
What Is Wrong With This Script?

I have writtin a script that, when executed, will check the viewers username and password against a file called UserList.js. But it has an error every time i execute it.

Here is the content of the script:

Code:
<script language="javascript" type="text/javascript" src="UserList.js">
function login()
{
var loggedin = false
var userin = document.getElementById('user').value
var passin = document.getElementById('pass').value
for (i=0;i<users.length;i++)
{
if (userin==users[i][0] && passin==users[i][1])
{
loggedin = true
break
}
else {}
}
if (loggedin==true)
{
alert("yay")
}
else
{
alert("Wrong username/password")
}
}
</script>
And this is the content of UserList.js:

Code:
var users = new Array();
users[0] = new Array("admin_control","securepassword");
users[1] = new Array("buttercup","cadbury");
users[2] = new Array("charley","cookies");
users[3] = new Array("crewdesign","canoe");
users[4] = new Array("footymadfrostie","elliott");
users[5] = new Array("haneebee","haneebee123");
users[6] = new Array("henry","thomas");
users[7] = new Array("ieuan","rugby");
users[8] = new Array("johnskorczewski","webpromotionweekly");
users[9] = new Array("sormesher","telcora");
users[10] = new Array("mark","76715288");
users[11] = new Array("besty","miffy");
users[11] = new Array("guest","guest");
users[12] = new Array("boycee","select");
users[13] = new Array("kyleblakemore","cresswell");
users[14] = new Array("dc120","united1");
users[15] = new Array("steven","steven");
users[16] = new Array("sxctom06","6++569");
users[17] = new Array("bob","teggin987");
users[18] = new Array("richard","richard")
Please help!
markster is offline   Reply With Quote
Old 06-13-2006, 11:33 AM   #2 (permalink)
Redline
PHP Student
 
Join Date: Oct 2004
Location: Forest Grove, OR
Posts: 150
Redline is on a distinguished road
Send a message via AIM to Redline Send a message via MSN to Redline
I got it to work with this code

HTML Code:
<script language="javascript" type="text/javascript" src="UserList.js"> </script>
<script language="javascript" type="text/javascript">
	function login() {
		var loggedin = false
		var userin = document.getElementById('user').value
		var passin = document.getElementById('pass').value
		for (i=0;i<users.length;i++) {
			if (userin==users[i][0] && passin==users[i][1]) {
				loggedin = true
				break
			} else {}
		}
		if (loggedin==true) {
			alert("yay")
		} else {
			alert("Wrong username/password")
		}
	}
</script>
Essentially specifying a source in a script tag seems to make it ignore everything within the opening/closing tags.

Now, using Javascript for user authentication is a major security problem. It's very easy for a user to view source, see where the user credentials are stored, and steal them. And your loggedin flag sits on the client. Seems too risky for me.
__________________
Current Project
Redline is offline   Reply With Quote
Old 06-13-2006, 11:42 AM   #3 (permalink)
markster
Code Monkey
 
markster's Avatar
 
Join Date: Jun 2006
Posts: 65
markster is on a distinguished road
THANKS! Dont worry, its not for anything major
markster is offline   Reply With Quote
Old 06-13-2006, 01:06 PM   #4 (permalink)
Redline
PHP Student
 
Join Date: Oct 2004
Location: Forest Grove, OR
Posts: 150
Redline is on a distinguished road
Send a message via AIM to Redline Send a message via MSN to Redline
Cool, no prob my friend
__________________
Current Project
Redline is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Weird Image Scrolling Script...Please Help mark4man HTML, XML, Javascript, AJAX 3 06-14-2005 07:51 AM
Executing a server script from PHP sde PHP 4 02-05-2005 11:12 AM
Something wrong with the view script redhead Lounge 1 10-11-2004 01:58 PM


All times are GMT -8. The time now is 10:06 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting