#1
  1. SBC Online Tech
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Somewhere between here and there
    Posts
    22
    Rep Power
    0

    Question Help with a java based script


    Ok I am new here and am very new to html and java. I did not write this script but it was free. I am trying to modify it. Basically when I create a user, password, and redirect page everything works EXCEPT the direct page. I have tried several options but nothing seems to work. Basically I want to be able to set up users, passwords and redirect pages up to 12 characters. When I got the script everything had to be exactly 8 characters. I have modified the password script to accept anything from 1 to 12, but when I setup a direct page name less than 12 characters it randomizes characters to make it 12. For example if I enter mypage it will redirect to mypageazaaaa.html any ideas? here is the script:

    <head>

    <title>Login Generator</title>

    </head>

    <!-- 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: http://www.iinet.net.au/~biab/ -->

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

    <!-- "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!=0 value=""></td></tr>
    <tr><td align=right>Password:</td><td><input type=text name=password size!=0 maxlength<12><font size="-1"><-- Can be up to 12 characters</font></td></tr>
    <tr><td align=right>Page Name:</td><td><input type=text name=pagename size!=0 maxlength<12><b>.html</b><font size="-1"><-- Can be up to 12 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 Can be up to 12 characters (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<12;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<12;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.\n\nThen, 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.\n\nQuestions about this script or how to put it on your site should be directed to it's author via email: dion@mailhub.omen.com.au\n\n*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<12;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<12;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>\n\n";
    html+="<!-- Original: Dion -->\n";
    html+="<!-- Web Site: http://www.iinet.net.au/~biab/ -->\n";
    html+="<!-- This script and many more are available free online at -->\n";
    html+="<!-- The JavaScript Source!! http://javascript.internet.com -->\n\n";
    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<12;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!=0 maxlength=12 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<12;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 -->
    </body>
  2. #2
  3. SBC Online Tech
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Somewhere between here and there
    Posts
    22
    Rep Power
    0
    Also I would only post the part of the script that is "defective...but I don't know what all is required to correct the issue as it has a long array at the bottom.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    7
    Rep Power
    0
    You aren't going to get anywhere fast if you don't start with the basics. It is silly to just copy and paste something you don't understand, and then ask other people to debug it. We want to help you, but if you don't follow the guidelines about posting you aren't going to get any help.

    Java != javascript.
  6. #4
  7. SBC Online Tech
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Somewhere between here and there
    Posts
    22
    Rep Power
    0

    well....


    I do understand most of it except the arrays.

    I have tried size!=0 maxcharacters=12 and <12
    The problem lies in the array somewhere I am sure as it tries to set the redirect page to 12 characters regardless of the earlier statement.

    I am not simply copying and pasting and saying "fix this for me"

    But I would like help isolating the array that is causing the problem.

    Thanks.
  8. #5
  9. Moderator Emeritus
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2002
    Location
    Austin, TX
    Posts
    7,196
    Rep Power
    2268
    This isn't JAVA, btw, its JavaScript - quite a different thing.
    DrGroove, Devshed Moderator | New to Devshed? Read the User Guide | Connect with me on LinkedIn
    The Most Important Article You Can Read as a Developer
  10. #6
  11. SBC Online Tech
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Somewhere between here and there
    Posts
    22
    Rep Power
    0
    I know this is a javascript. That is why I said java based script and posted this in the html, javascript, and CSS forum instead of the Java Servlet forum.

    I simply cannot understand why my destination page keeps coming up with 16 characters regardless of the input. And if the input is less than 16 characters it randomizes the remaining to equal 16.
  12. #7
  13. No Profile Picture
    The New User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    109
    Rep Power
    15
    You just said it goes up to 12 characters in your first and second post, but now say it goes to 16? Are you counting the ".html" now? Anyways, try using:
    Code:
     for (var i=0;i<12 && i<params[2].length;i++)
    That will kill the for loop after all chars from the string have been run thru. Otherwise, it will continously run the script up to i=11, no matter how many chars are in params[2]. Also, I would suggest using string.charAt(i) instead of string.substring(i,i+1), but thats just me

    Hope that helps.
    --Neil

    Edit: Just for future information, this is not "A javascript". It is actually a JavaScript script... JavaScript is a web-language developed by Netscape that has no relation to Java other than name. Just thought u'd like to know before someone bites your head off.
    Last edited by knew youzr; August 15th, 2003 at 06:06 PM.
  14. #8
  15. SBC Online Tech
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Somewhere between here and there
    Posts
    22
    Rep Power
    0
    Thanks for the help and clarification. I do support on forums, very similar to this one (see posting sig) but as I said am very new to html, java, etc. Thanks I will try modifying this javascript script and see how it does.
  16. #9
  17. SBC Online Tech
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Somewhere between here and there
    Posts
    22
    Rep Power
    0
    Just so you know, that fixed it. Thanks a bunch.

IMN logo majestic logo threadwatch logo seochat tools logo