PDA

View Full Version : Login Code Issue


Forgotten
07-08-2004, 05:03 PM
Hello again everyone. I am currently selling templates thanks to this website for giving me a nudge in the butt. And I am creating a current template that is using CSS HTML Java and Php(soon). The java login code is not working the correct fasion, it will not go to the successpage. This is a big problem. This is a cookie login script so it is a little more ocmplex. Being this my first time making a javascript login code, I thought atleat someone can help me out.

Here is the JS Code:


//----------------------------------------------------------------
// Usernames, Passwords & User Pages
//----------------------------------------------------------------
var successpage = "http://b0x2.b0x.com/staff_passvert.html";
var loginpage = "http://b0x2.b0x.com/index.html";

var imgSubmit = "http://b0x2.b0x.com/images/b_go.gif";
var imgReset = "";

var users = new Array();

users[0] = new Array("justin","922justin",""); //Note: the blank "" in these values are for single user page.
users[1] = new Array("jeff","pktimes",""); //Note: the blank "" in these values are for single user page.

//----------------------------------------------------------------
// Login Functions
//----------------------------------------------------------------
function login(username,password){
var member = null;
var loggedin = 0;
var members = users.length;
for(x=0;x<members && !loggedin; x++){
if((username==users[x][0])&&(password==users[x][1])){
loggedin = 1;
member = x;
break; // User validated, terminate the for loop.
}
}

if(loggedin==1){
if(users[member][2] != "") {
successpage = users[member][2];
}
setCookie("login",1);
if (top.location.href != location.href){
location.href = successpage;
}else{
top.location.href = successpage;
}
}else{
alert('Invalid Password or Username');
}
}

function logout() {
deleteCookie("login");
if (top.location.href != location.href){
location.href = loginpage;
}else{
top.location.href = loginpage;
}
}

//----------------------------------------------------------------
// Cookie Handler
//----------------------------------------------------------------
var ckTemp = document.cookie;

function setCookie(name, value) {
if (value != null && value != "")
document.cookie=name + "=" + escape(value) + ";";
ckTemp = document.cookie;
}

function deleteCookie(name) {
if (getCookie(name)) {
document.cookie = name + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}

function getCookie(name) {
var index = ckTemp.indexOf(name + "=");
if(index == -1) return null;
index = ckTemp.indexOf("=", index) + 1;
var endstr = ckTemp.indexOf(";", index);
if (endstr == -1) endstr = ckTemp.length;
return unescape(ckTemp.substring(index, endstr));
}

function checkCookie() {
var temp = getCookie("login");
if(!temp==1) {
alert('Invalid Password or Username');
if(top.location.href != location.href){
location.href = loginpage;
}else{
top.location.href = loginpage;
}
}
}

//----------------------------------------------------------------
// Login Panel
//----------------------------------------------------------------

function BuildPanel() {
document.write('<form name="logon"><table align="left" border="0"><tr><td align="right">');
document.write('<small><font face="Verdana"></font></small></td>');
document.write('<td><small><font face="Verdana"><input type="text" name="username" size="15" value="USERNAME"></font></small></td></tr>');
document.write('<tr><td align="right"><small><font face="Verdana"></font></small></td>');
document.write('');
if(imgSubmit == ""){
document.write('<td><small><font face="Verdana"><input type="password" name="password" size="10" value=""></font></small>&nbsp;&nbsp;'+
'<input type="button" value="Logon" name="Logon" onclick="login(username.value,password.value)"></td></tr>');
} else {
document.write('<td><small><font face="Verdana"><input type="password" name="password" size="10" value=""></font></small>&nbsp;&nbsp;'+
'<input type="image" src="'+imgSubmit+'" name="Logon" onclick="login(username.value,password.value)"></td></tr>');
}
if(imgReset == ""){
document.write('');
} else {
document.write('');
}
document.write('</p></td></tr></table></form>');
}



~Forgotten


(edited to reduce horizontal scrolling a little)

¥åßßå
07-08-2004, 05:09 PM
"justin","922justin"

Hmmmmm, I wonder what your username and password are ?

You REALLY want to be doing any authentication server side

agent002
07-08-2004, 05:25 PM
Originally posted by ¥åßßå
Hmmmmm, I wonder what your username and password are ?

You REALLY want to be doing any authentication server side
Well, there is one sort of JavaScript authentication that I believe is completely secure, if it isn't, please tell me the password for it :)
http://members.surfeu.fi/jerkku/htmlforums/login.html

I would still do the login in server side (Perl, PHP, ASP, Python, etc.) though. You can't have a registration form with JavaScript either because it has nowhere to store the info; it can't modify any information on a server.

P.S. ¥åßßå, as a Finno-Swede that knows some German, I read your name as "yosso" :cool:

¥åßßå
07-08-2004, 05:36 PM
Originally posted by agent002
Well, there is one sort of JavaScript authentication that I believe is completely secure, if it isn't, please tell me the password for it :)
http://members.surfeu.fi/jerkku/htmlforums/login.html
.......
I read your name as "yosso"

Lol, that's not "entirely" javascript authentication though is it ;)

Isn't "yosso" Greek slang for hello or something? Lol, my names not going to know what it is soon !

Forgotten
07-08-2004, 09:12 PM
so would it be best to create a PHP login script? If so can anyone give me a hand?

agent002
07-09-2004, 01:18 AM
Well, if your host supports .htaccess, then you could use that to create a password protected area. It is easy to set up but hardly customizable at all and if you wish to have a registration page, it still needs a script. So, yes, if your host supports PHP, then use that. Here (http://www.evolt.org/article/PHP_Login_Script_with_Remember_Me_Feature/17/60265/) is a tutorial that I found, if you don't like it, search Google for another.

Forgotten
07-09-2004, 12:52 PM
yay! lucky me, I have FTP access and the .htaccess file. So may I see the tutorial?

agent002
07-09-2004, 12:58 PM
err... the word "Here" in my previous post is a link to it :)

Forgotten
07-09-2004, 04:00 PM
oh thankyou