View Full Version : help with logging in script please

05-27-2006, 10:58 AM
I'm looking for the right javascript that will help me with a log in and password ... scripty thing. I've set up my forms, username and password, and my Log In button. My passwords and usernames are stored in the script. What I need now is that when they are accepted, all the pages of my website are updated with the words, "welcome *username*" somewhere on the page. That's all I'd like to happen. Nothing like editing profiles and their own page or stuff like that; this is just for a small project. Just a welcome *username* message.

This is the script i am using. I just don't know what else I need to put in to make this work. Am i using the wrong script for what I want to happen? I have a feeling that the destination pages are wrong for what i want to happen... I am really not good at javascript at all unfortunately!

Help WOULD be appreciated! I need this in the next two days!


<!-- Begin
function Login(){
var done=0;
var username=document.login.username.value;
var password=document.login.password.value;
if (username=="member1" && password=="password1") {
window.location="index.html"; done=1; }
if (username=="member2" && password=="password2") {
window.location="index.html"; done=1; }
if (username=="member3" && password=="password3") {
window.location="index.html"; done=1; }
if (done==0) { alert("Invalid login!"); }
// End -->

Insert into <BODY>
<form name=login>
<table width=225 border=1 cellpadding=3>
<tr><td colspan=2>
<p align="center"><font size="+2"><b>Log in!</b></font></p>
<tr><td>Username:</td><td><input type=text name=username></td></tr>
<tr><td>Password:</td><td><input type=password name=password></td></tr>
<tr><td colspan=2 align=center><input type=button value="Login!" onClick="Login()"></td></tr>

Philip M
05-27-2006, 05:38 PM
If you had used the search facility you would have found that the same question had been asked and answered already this week alone.

If all you want is "Welcome UserName" then you should store UserName in a cookie on the client computer. Anything else really requires server side programming. But see also


which is probably secure enough for your purposes. I take it that you realise that storing the user names and passwords within the script is very insecure indeed and easily circumvented by anyone who knows even a smattering of JavaScript.

05-27-2006, 05:42 PM
I'm sorry Philip M if I have wasted your time, but thank you very much for your help.

Yes I realise the insecurity of storing passwords in the script, which is why I am only going to use this as a trial until my scripting skills increase.

Once again i apologise.

Philip M
05-27-2006, 08:56 PM
No need to grovel - but please do use the search feature in future as a starting point.

This explains how to set and read a cookie containing username:-


05-28-2006, 02:26 AM
ah! thankyou very much!

05-28-2006, 08:03 AM
Can this be done without using a testing server? If so, how do I go about it? I apologise - my knowledge of cookies and javascript is minimum.