/    Sign up×
Community /Pin to ProfileBookmark

Password Protection for my website?

I found a rather nice script on the internet for a login page with multiple passwords and user names. It doesn’t really matter if the passwords are encryted or not.

When the user logs in correctly, it redirects them to a certain web page.

[B]The problem is[/B], I want to set a cookie for those who log in correctly. The script that I found does not have a cookie, and i was wondering if it is possible for anybody to add a very simple cookie to the script if the user logs in correctly.
[B]This is because right now[/B], anybody with the URL can access the supposed “member only” page. I want that so only those who logged in can see the “members only” page.

Below is the unaltered script I found on the internet. It is actually a script creator, and what it creates is what I paste into my BODY.

[COLOR=Navy][COLOR=Navy]<!– ONE STEP TO INSTALL LOGIN CODER:

  • 1. Add the first code into the BODY of your HTML document –>
  • <!– STEP ONE: Add the first code into the BODY of your HTML document –>

    <BODY>

    <center><table border=1>
    <tr><form name=members><td rowspan=4>
    <select name=memlist size=10 onChange=”showmem(this.form)”>

    <!– Original: Dion –>
    <!– Web Site: [url]http://www.iinet.net.au/~biab/[/url] –>

    <!– This script and many more are available free online at –>
    <!– The JavaScript Source!! [url]http://javascript.internet.com[/url] –>

    <!– “member name | password | destination pagename |” –>
    <option selected value=”John Smith|password|mainpage|”>John Smith
    <option value=”Peter Jones|theirpwd|endpages|”>Peter Jones
    <option value=”Sue Brown|asdfvcxz|nowheres|”>Sue Brown
    <option value=”Sally West|zaqxswde|logintop|”>Sally West
    </select></td>
    <td align=right>User:</td><td><input type=hidden value=”0″ name=entry>
    <input type=text name=memname size=8 value=””></td></tr>
    <tr><td align=right>Password:</td><td><input type=text name=password size=8 maxlength=8><font size=”-1″><– Must be exactly 8 characters</font></td></tr>
    <tr><td align=right>Page Name:</td><td><input type=text name=pagename size=8 maxlength=8><b>.html</b><font size=”-1″><– Must be exactly 8 characters</font></td></tr>
    <tr><td colspan=2 align=center>
    <input type=button value=”New User” onclick=”addnew(this.form);”>
    <input type=button value=”Delete User” onclick=”delthis(this.form);”>
    <input type=button value=”Update/Show Coding” onclick=”update(this.form); create(this.form);”></td></tr>
    <tr><td colspan=3 align=center>
    <input type=text size=60 name=message value=”Note: Password/Page Name must be exactly 8 letters! (a-z)”>
    <input type=hidden name=num value=1></td>
    </form></tr>
    </table>
    <hr size=2 width=75%>
    <form name=js><textarea cols=75 rows=10 name=scrpt wrap=virtual>
    <SCRIPT LANGUAGE=”JavaScript”>
    <!– Begin
    var params=new Array(4);
    var alpha=”ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI”;
    function check(form) {
    which=form.memlist.selectedIndex;
    choice = form.memlist.options[which].value+”|”;
    if (choice==”x|”) {
    alert(“Please Select Your Name From The List”);
    return;
    }
    p=0;
    for (i=0;i<3;i++) {
    a=choice.indexOf(“|”,p);
    params[i]=choice.substring(a,p);
    p=a+1;
    }
    h1=makehash(form.pass.value,3);
    h2=makehash(form.pass.value,10)+” “;
    if (h1!=params[1]) {
    alert(“Incorrect Password!”); return; };
    var page=””;
    for (var i=0;i<8;i++) {
    letter=params[2].substring(i,i+1)
    ul=letter.toUpperCase();
    a=alpha.indexOf(ul,0);
    a-=(h2.substring(i,i+1)*1);
    if (a<0) a+=26;
    page+=alpha.substring(a,a+1); };
    top.location=page.toLowerCase()+”.html”;
    }
    function makehash(pw,mult) {
    pass=pw.toUpperCase();
    hash=0;
    for (i=0;i<8;i++) {
    letter=pass.substring(i,i+1);
    c=alpha.indexOf(letter,0)+1;
    hash=hash*
    mult+c;
    }
    return(hash);
    }
    // End –>
    </script>
    </textarea>
    </form>
    <SCRIPT LANGUAGE=”JavaScript”>
    <!– Begin
    var params=new Array(4);
    var script=document.js.scrpt.value;
    document.js.scrpt.value=”Create your users, their passwords, and their destination pages using the form above.nnThen, click ‘Show Coding’ to see the login HTML and JavaScript that you need to put on your page to password-protect your site with that info.nnQuestions about this script or how to put it on your site should be directed to it’s author via email: [email][email protected][/email]nn*Honestly, we don’t even totally understand this JavaScript!*“;
    var alpha=”ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI”;
    showmem(document.members);
    function showmem(form) {
    document.members.num.value=document.members.memlist.length;
    var which=form.memlist.selectedIndex;
    splt(form.memlist[which].value);
    form.entry.value=which+1;
    for (i=2;i<5;i++) {
    form.elements[i].value=params[i-2]; };
    }
    function splt(choice) {
    p=0;
    for (i=0;i<3;i++) {
    a=choice.indexOf(“|”,p);
    params[i]=choice.substring(a,p);
    p=a+1;
    }
    }
    function addnew(form) {
    newmem=getfields(form);
    var who=prompt(“New User’s Name:”,””);
    form.memlist[form.memlist.length] = new Option(who, newmem, false, true);
    if (navigator.appName==”Netscape”) {
    document.js.scrpt.value=script;
    history.go(0);
    }
    else {
    showmem(document.members);
    }
    }
    function getfields(form) {
    newmem=””;
    for (i=2;i<5;i++) {
    newmem+=form.elements[i].value+”|”; };
    for (i=3;i<5;i++) {
    a=form.elements[i];
    for (k=0;k<8;k++) {
    }
    }
    return(newmem);
    }
    function delthis(form) {
    if (confirm(“Delete “+form.memname.value+”?”)) {
    form.memlist.options[form.entry.value-1]=null;
    form.message.value=form.memname.value+” Deleted”;
    form.memlist.selectedIndex=0;
    if (navigator.appName==”Netscape”) {
    document.js.scrpt.value=script;
    history.go(0);
    }
    else {
    showmem(document.members);
    }
    }
    }
    function update(form) {
    msg=”no”;
    a=form.elements[i];
    for (k=0;k<8;k++) {
    b=a.value.substring(k,k+1);
    c=b.toUpperCase();
    form.memlist[form.entry.value-1].value=getfields(form);
    form.message.value=form.memname.value+”‘s record was updated”;
    }
    }
    function create(form) {

    var html=”<center><form name=login>n”;
    html+=”<table border=1 cellpadding=3>nn”;
    html+=”<!– Original: Dion –>n”;
    html+=”<!– Web Site: [url]http://www.iinet.net.au/~biab/[/url] –>n”;
    html+=”<!– This script and many more are available free online at –>n”;
    html+=”<!– The JavaScript Source!! [url]http://javascript.internet.com[/url] –>nn”;
    html+='<tr><td colspan=2 align=center><font size=”+2″>’;
    html+='<b>Members-Only Area!</b></font></td></tr>n’;
    html+=”<tr><td>Username:</td><td><select name=memlist>n<option value=’x’>”;
    for (j=0;j<form.memlist.length;j++) {
    splt(form.memlist.options[j].value);
    h1=makehash(params[1],3);
    h2=makehash(params[1],10)+” “;
    var page=””;
    for (var i=0;i<8;i++) {
    letter=params[2].substring(i,i+1);
    ul=letter.toUpperCase();
    a=alpha.indexOf(ul,0);
    a+=(h2.substring(i,i+1)*1);
    page+=alpha.substring(a,a+1);
    }
    html+=”n<option value='”+params[0]+”|”+h1+”|”+page+”‘>”+params[0];
    };
    html+=”n</select></td></tr>n”;
    html+=”<tr><td>Password:</td><td><input type=password size=10 maxlength=8 name=pass></td></tr>n”;
    html+='<tr><td colspan=2 align=center><input type=button value=”Login” onclick=”check(this.form)”></td>n’;
    html+=”</tr>n</table>n</form>n”;
    document.js.scrpt.value=html+script+”</center>”;
    }
    function makehash(pw,mult) {
    pass=pw.toUpperCase();
    hash=0;
    for (i=0;i<8;i++) {
    letter=pass.substring(i,i+1);
    c=alpha.indexOf(letter,0)+1;
    hash=hash*
    mult+c;
    }
    return(hash);
    }
    // End –>
    </script>
    </center>

    <p><center>
    <font face=”arial, helvetica” size=”-2″>Free JavaScripts provided<br>
    by <a href=”http://javascriptsource.com”>The JavaScript Source</a></font>
    </center><p>

    <!– Script Size: 6.50 KB –>[/COLOR][/COLOR]

    Thanks in advance.

    to post a comment
    JavaScript

    1 Comments(s)

    Copy linkTweet thisAlerts:
    @TNONov 25.2006 — Personally I've had the best use of the following script for password protection:

    <html>

    <head>

    <script type="text/javascript">

    function OneWay(S) { var j, x, y = 2e50

    x = '0.'+parseInt(S.value, 36)

    with (Math) { for (j=0;j<10;j++) x = tan(1+x+x*y%1)%1 }

    // modify that to keep argument in about 0.25..1.25

    return ((x+1)/2).toString(36).substring(2)+".html" }

    </script>

    </head>

    <body>

    <input type="text" id="Pwrd" value="" size=19><button onClick="document.location.replace( OneWay(document.getElementById('Pwrd').value))">LogIn</button>

    </body>

    </html>

    The only way someone could get in is if they knew what the password/webpage was for the member page and trying to deduce it from this function is difficult to say the least.

    Almost forgot, heres a rundown on cookies: http://www.quirksmode.org/js/cookies.html
    ×

    Success!

    Help @frankkthetank spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...