#fcleft">




Many of you like the Javascript Password script, but complain that you can't store the password so the user doesn't need to enter it in every time he accesses your page. This script calms those complaints. The Javascript Password (Cookie Enabled) stores what the user entered in for the password and will greet him with a "Welcome Back" message (if he entered in the password correctly) instead of a "Enter in the Password" prompt.
The source...


<script language="JavaScript">

<!--
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.javascript-page.com

    function getCookieVal (offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
    }

    function GetCookie (name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
    }
    return null;
    }

    function SetCookie (name, value) {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
    }

    function DeleteCookie(name) {
    var exp = new Date();
    FixCookieDate (exp); 
    exp.setTime (exp.getTime() - 1); 
    var cval = GetCookie (name);
    if (cval != null)
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
    }

    var d = GetCookie("de")
    var paswd = "real"

    if (d == paswd) {
    alert("Password confirmed \n \n Welcome back!")
    location= "cright.html"
    }

    if (d == null || d != paswd) {
    check_in()
    }
    
    function check_in() {
    var f = prompt("Enter password to proceed. [pass is 'real']","")
    var thenewdate = new Date ();
    thenewdate.setTime(thenewdate.getTime() + (365 * 24 * 3600 * 1000));
    SetCookie('de',f,thenewdate);
    var e = GetCookie('de');
    
    if (e == paswd) {
      alert("Password confirmed \n \n You will not have to enter in the password when you come back")
      location= "cright.html"
      }

    else {
      alert("You have not entered the password correctly. \n \n However, you can still access the page to find out the script at the next page.")
      location = "cwrong.html"
      // you could substitute the previous line with "history.back()"
      }
    }

//-->

</script>


Color coding...


This is the password.
This is the text that appears when the user is prompted.
Replace this with the URLs the user gets if the password is right or wrong.