Computing.Net > Forums > Programming > Javascript

Javascript

Reply to Message Icon

Original Message
Name: lime_sub
Date: April 26, 2002 at 18:51:35 Pacific
Subject: Javascript
Comment:

I wonder i am in the right place to ask about javascript questions:
how do i code some page that
Users enter their login name and password
then the the script will open up a page for them.
Each user will have their particular page.
What i am try to do here is to do a manually coded database for each user.
Thanks


Report Offensive Message For Removal


Response Number 1
Name: Tom
Date: April 26, 2002 at 20:23:16 Pacific
Subject: Javascript
Reply: (edit)

Well, you're not the first here to ask a JavaScript question =)
It is possible to do that with JavaScript, but since it's a client-side language, it will be very insecure. Maybe you should try using a server-side language such as ASP, PERL or PHP.


Report Offensive Follow Up For Removal

Response Number 2
Name: Jasmine
Date: April 27, 2002 at 00:02:42 Pacific
Subject: Javascript
Reply: (edit)

Hey Tom, I bet you might be able to answer these questions of mine bout java script too :)
well i am confused of the codes in using form for password protection to my own homepage, can i do that?
I know the source for password and user, but how can the web verify their password is right or wrong?
what i really want is, to enter to the homepage, the user have to put in a correct password,... :P


Report Offensive Follow Up For Removal

Response Number 3
Name: lime_sub
Date: April 27, 2002 at 08:37:42 Pacific
Subject: Javascript
Reply: (edit)

hey jasmine,
the web verify it your username and password wrong? Then you better recheck you HTML and Your javascript. they must be exactly the same. not even a single space
EX : (password) not (password ) <--a spacing

And Tom ,
i know its very insecure but i still want to do it. Because there is nothing private in my webpage. besides my webpage doesn't need $$$ to maintain. So it doesn';t support perl.
So can you help me with the coding on what i mention? Thanks


Report Offensive Follow Up For Removal

Response Number 4
Name: Tom
Date: April 27, 2002 at 10:04:55 Pacific
Subject: Javascript
Reply: (edit)

Alright then, hopefully this will answer both of your questions.

You should have 2 arrays, one for the usernames, and one for the passwords. The corresponding password should be in the same place in the password array, as the username is in the username array. ie:
user[0] = "fred";
pass[0] = "fred's password";
user[1] = "steve";
pass[1] = "steve's password";
And so on. To get the username/password, you could either use:
var username = prompt("Enter username");
var password = prompt("Enter password");
or:
function getuser(){
var username = document.forms.userform.user.value;
var password = document.forms.userform.pass.value;
}
With the getuser() method, you should have an HTML form with name="userform", and 2 text inputs within the form, one name="user", and the other name="pass". With the password input, you could use type="password" instead of type="text". You would also have an input type="button" onClick="getuser()" (I can't type HTML tags on this board). You would then have a for loop:
var auth = false;
for(i = 0; i < x; i++){
if(username == user[i] && password == pass[i]){
auth = true;
// Whatever you want to do when authenticated, ie:
alert("Hello " + user[i] + "!");
location.href = "protected.html";
break;
}
}
if(!auth){
alert("invalid user/pass");
}
x should be the amount of users in total, the length of the arrays. If you were using the getuser() method, this loop should be inside the function.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Javascript

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge