Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

user logging and Password Protection external .js

Status
Not open for further replies.

emilly

Technical User
Sep 7, 2007
2
SI
Hello everybody,

I need a little help and I will appreciate is anybody can help me with that.

I need to set up a user logging and password in an external .js file

Here what I wrote:

my loggin.js

function loggin(){
var done=0;
var username=document.login.username.value;
username=username.toLowerCase();
var password=document.login.password.value;
password=password.toLowerCase();
if (username=="member1" && password=="eldi") { window.location="page1.htm"; done=1; }
if (username=="member2" && password=="password2") { window.location="page2.html"; done=1; }
if (username=="member3" && password=="password3") { window.location="page3.html"; done=1; }
if (done==0) { alert("Invalid login!"); }
}

My HTML file

<form name=login>
<table width=225 border=1 cellpadding=3>
<tr><td colspan=2><center><font size=&quot;+2&quot;><b>Members-Only Area!</b></font></center></td></tr>
<tr><td>Username:</td><td><input type=text name=username></td></tr>
<tr><td>Password:</td><td><input type=text name=password></td></tr>
<tr><td colspan=2 align=center><input type=button value=&quot;Login!&quot; onClick=&quot;loggin()&quot;></td></tr>
</table>
</form>
</center>

Please anybody can help me with that?
Thank you in advance,
Emilly
 
I dont think there is any way in which you can prevent user's from seeing the JavaScript code as of now. Even if you put it in a seperate .js file, the user can look up the path/name of the file, download the file and look at your code. Just that its a little more difficult than putting the script in the page itself. This means that they would be able to see the list of username/passwords.

Generally, login validation is done on the server side using server side scripting languages.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top