Login script help

Discussion in 'Javascript' started by iwasinnihon@hotmail.com, Apr 22, 2006.

  1. Guest

    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>');
    }
    , Apr 22, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William F. Robertson, Jr.
    Replies:
    0
    Views:
    430
    William F. Robertson, Jr.
    Jul 2, 2003
  2. =?Utf-8?B?Sm9l?=

    Need some help with login script

    =?Utf-8?B?Sm9l?=, Nov 15, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    394
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Nov 16, 2004
  3. Rajat
    Replies:
    3
    Views:
    680
    Jorgen Grahn
    Jan 8, 2010
  4. VYAS ASHISH M-NTB837
    Replies:
    2
    Views:
    544
    Jan Kaliszewski
    Jan 7, 2010
  5. julietta carpentieri

    Help with Password Login Script

    julietta carpentieri, Mar 16, 2005, in forum: Javascript
    Replies:
    3
    Views:
    156
    julietta carpentieri
    Mar 17, 2005
Loading...

Share This Page