Login script help

I

iwasinnihon

I have written a login script to login into a website I am building.
However, I am having trouble figuring out how to connect to a database
and check the users off that database. My database is in MS Access and
saved as a .mbd file. It has only one table and two fields in that
table. Here is my javascript code. Any ideas on what I can do to get
it to pull the user/password info from the table.

var successpage = "admintest.html";
var loginpage = "index.html";

var imgSubmit = "";
var imgReset = "";

var users = new Array();

users[0] = new Array("1","1","");
users[1] = new Array("username2","password2","");


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;
}
}

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('access denied');
}
}

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


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('access denied');
if(top.location.href != location.href){
location.href = loginpage;
}else{
top.location.href = loginpage;
}
}
}



function BuildPanel() {
document.write('<form name="logon"><table align="center"
border="0"><tr><td align="center">');
document.write('<small><font face="Arial"
color="white">Username:</font></small></td>');
document.write('<td><small><font face="Verdana"><input type="text"
name="username" size="15"></font></small></td></tr>');
document.write('<tr><td align="right"><small><font face="Arial"
color="white">Password:</font></small></td>');
document.write('<td><small><font face="Verdana"><input type="password"
name="password" size="15"></font></small></td></tr>');
if(imgSubmit == ""){
document.write('<tr><td align="center" colspan="2"><p><input
type="button" value="Logon" name="Logon"
onclick="login(username.value,password.value)">');
} else {
document.write('<tr><td align="center" colspan="2"><p><input
type="image" src="'+imgSubmit+'" name="Logon"
onclick="login(username.value,password.value)">');
}
if(imgReset == ""){
document.write('<input type="reset" value="Reset" name="Reset">');
} else {
document.write('<input type="image" src="'+imgReset+'" name="Reset"
onclick="logon.reset();">');
}
document.write('</p></td></tr></table></form>');
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top