Advanced Search

Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: Login Password Script Help

  1. #1
    Join Date
    Feb 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Login Password Form Help

    I need help with a login and password form.
    I have one that works listed below, but it only works when you click the login button - I need it to ALSO work when you press ENTER. I tried to change the onClick to onKeyPress, but no luck - please advise. I do not need to stay with this form if anyone has a better recommendation.

    thanks!

    <script language="javascript">
    <!--//
    /*This Script allows people to enter by using a form that asks for a
    UserID and Password*/
    function pasuser(form) {
    if (form.id.value=="member") {
    if (form.pass.value=="gopass") {
    location="gopass.htm"
    } else {
    alert("Invalid Password")
    }
    } else { alert("Invalid UserID")
    }
    }
    //-->
    </script>
    <form name="login">
    <span class="style13">Username: </span>
    <input name="id" type="text" size="15">
    <br>
    <span class="style13">Password: </strong></span>
    <input name="pass"type="password" size="15">
    <input type="button" value="Login" onClick="pasuser(this.form)">
    </form>

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try this:

    Code:
    <script language="javascript">
    <!--//
    /*This Script allows people to enter by using a form that asks for a
    UserID and Password*/
    function pasuser(form) {
    if (form.id.value=="member") {
    if (form.pass.value=="gopass") {
    location="gopass.htm"
    } else {
    alert("Invalid Password")
    }
    } else { alert("Invalid UserID")
    }
    }
    //-->
    </script>
    <form name="login" onsubmit="pasuser(this.form)">
    <span class="style13">Username: </span>
    <input name="id" type="text" size="15">
    <br>
    <span class="style13">Password: </strong></span>
    <input name="pass"type="password" size="15">
    <input type="submit" value="Login">
    </form>
    Notice I changed the button to a submit button, then added the onsubmit handler to the form tag.

    Also notice, this does not belong in the HTML forum but instead in the javascript forum.

    Anyway, hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jan 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Please try this:
    --------------------------------------------------
    <HTML>
    <HEAD>
    <META HTTP-EQUIV="Expires" CONTENT="-1">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <TITLE>Ear Demo</TITLE>
    <script language="javascript">
    <!--//
    /*This Script allows people to enter by using a form that asks for a
    UserID and Password*/
    function pasuser(form) {
    if (form.id.value == "member") {
    if (form.pass.value == "gopass") {
    location = "gopass.htm";
    } else {
    alert("Invalid Password");
    }
    } else {
    alert("Invalid UserID");
    }
    }
    function IEKeyCap() {
    if (window.event.keyCode == 13) {
    pasuser(document.forms[0]) ;
    }

    }

    //-->
    </script>
    <body onKeyPress="IEKeyCap()">
    <form name="login">
    <span class="style13">Username: </span>
    <input name="id" type="text" size="15">
    <br>
    <span class="style13">Password: </strong></span>
    <input name="pass"type="password" size="15">
    <input type="button" value="Login" onClick="pasuser(this.form)">
    </form>
    </body>
    </HTML>

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Please don't -- that's a terrible script (and pretty bad HTML too). The correct way to do it is to use the form's onsubmit event rather than the button's onclick.

    Javascript password scripts will always be less secure than their server-side counterparts, but it is at least possible to make them slightly secure (I.E. not including the password in the source) -- see http://www.twey.co.uk/?q=encpass for an example.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Quote Originally Posted by Twey View Post
    The correct way to do it is to use the form's onsubmit event rather than the button's onclick.
    I had suggested that in this thread. According to the OP, it did not work.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. #6
    Join Date
    Feb 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Almost got it Twey

    The script on your site is perfect, I just can't figure out where to put the page that the form goes to? right now it goes nowhere. Sorry if this is a stupid question I am very new to javascript.

    thanks, Isadora

    here is the script I used: (username: member - password:gopass)

    <script type="text/javascript">

    // Encrypted Password script - by Twey, http://www.twey.co.uk/
    // (only slightly based on the script of the same name by Rob Heslop)
    // Released under the terms of the GNU General Public License,
    // version 2 or later. See http://www.gnu.org/copyleft/gpl.html for more
    // information.

    var caseSensitive = true;
    var pageToGoTo = "includes/%p.txt"; // %u will be replaced with username, %p with password.
    var failureMessage = "Username/password combination entered incorrectly."
    var caseWarning = "\nWarning: case sensitive.";
    var users = [
    ["aa08769cdcb26674c6706093503ff0a3", "400a2c1559d060aec45227533f363d2d"]
    // Add more here, in the format [usercode, passcode]
    // but don't forget to add a comma to all but the last one!
    ];

    function encrypt(str) {
    /* Original algorithm:

    var hash = 1;
    for(var i=0;i<str.length;i++) hash *= str.charCodeAt(i);
    return hash;

    */
    /* Paj's MD5 implementation: */
    // NOTE: MD5 has several collision weaknesses. However,
    // these are not an issue here, as succeeding in creating
    // a collision would only cause the script to report the
    // correctness of the password incorrectly.

    return hex_md5(str);
    }

    function passCheck(frm, user, pass) {
    var form = document.forms[frm] || frm,
    username = user ? (form && form.elements[user] ? form.elements[user].value : user) : form.elements["username"].value,
    password = pass ? (form && form.elements[pass] ? form.elements[pass].value : pass) : form.elements["password"].value,
    passcode = usercode = 1;
    if(!caseSensitive) {
    username = username.toLowerCase();
    password = password.toLowerCase();
    }
    var pg = pageToGoTo.replace(/%p/g, password).replace(/%u/g, username);
    passcode = encrypt(password);
    usercode = encrypt(username);
    for(var i = 0; i < users.length; i++)
    if(users[i][0] == usercode && users[i][1] == passcode) {
    if(!frm) return window.location.href = pg;
    form.action = pg;
    return true;
    }
    window.alert(failureMessage + (caseSensitive ? caseWarning : ""));
    return false;
    }
    </script>

    <form action="" onsubmit="return passCheck(this);">
    <p>
    <label style="display:block;">
    Username:
    <input type="text" name="username" size="15">
    </label>
    <label style="display:block;">
    Password:
    <input type="password" name="password" size="15">
    </label>
    <input type="submit" value="Submit">
    </p>
    </form>

  7. #7
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Code:
    <script type="text/javascript">
    
    // Encrypted Password script - by Twey, http://www.twey.co.uk/
    // (only slightly based on the script of the same name by Rob Heslop)
    // Released under the terms of the GNU General Public License,
    // version 2 or later. See http://www.gnu.org/copyleft/gpl.html for more
    // information.
    
    var caseSensitive = true;
    var pageToGoTo = "includes/&#37;p.txt"; // %u will be replaced with username, %p with password.
    var failureMessage = "Username/password combination entered incorrectly."
    var caseWarning = "\nWarning: case sensitive.";
    var users = [
    ["aa08769cdcb26674c6706093503ff0a3", "400a2c1559d060aec45227533f363d2d"]
    // Add more here, in the format [usercode, passcode]
    // but don't forget to add a comma to all but the last one!
    ];
    
    function encrypt(str) {
    /* Original algorithm:
    
    var hash = 1;
    for(var i=0;i<str.length;i++) hash *= str.charCodeAt(i);
    return hash;
    
    */
    /* Paj's MD5 implementation: */
    // NOTE: MD5 has several collision weaknesses. However,
    // these are not an issue here, as succeeding in creating
    // a collision would only cause the script to report the
    // correctness of the password incorrectly.
    
    return hex_md5(str);
    }
    
    function passCheck(frm, user, pass) {
    var form = document.forms[frm] || frm,
    username = user ? (form && form.elements[user] ? form.elements[user].value : user) : form.elements["username"].value,
    password = pass ? (form && form.elements[pass] ? form.elements[pass].value : pass) : form.elements["password"].value,
    passcode = usercode = 1;
    if(!caseSensitive) {
    username = username.toLowerCase();
    password = password.toLowerCase();
    }
    var pg = pageToGoTo.replace(/%p/g, password).replace(/%u/g, username);
    passcode = encrypt(password);
    usercode = encrypt(username);
    for(var i = 0; i < users.length; i++)
    if(users[i][0] == usercode && users[i][1] == passcode) {
    if(!frm) return window.location.href = pg;
    form.action = pg;
    return true;
    }
    window.alert(failureMessage + (caseSensitive ? caseWarning : ""));
    return false;
    }
    </script>
    
    <form action="" onsubmit="return passCheck(this);">
    <p>
    <label style="display:block;">
    Username:
    <input type="text" name="username" size="15">
    </label>
    <label style="display:block;">
    Password:
    <input type="password" name="password" size="15">
    </label>
    <input type="submit" value="Submit">
    </p>
    </form>
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  8. #8
    Join Date
    Feb 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default ???

    OK but how do I save my page gohome.html as /includes/Gopass.txt?username=Member&password=Gopass

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I don't think you quite understand the nature of the script. What makes it secure is that it directs to a page whose name is based on the login info provided. It's a frontend to what could be considered a very basic form of server-side security built in to every webserver.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Code:
    <script type="text/javascript">
    
    // Encrypted Password script - by Twey, http://www.twey.co.uk/
    // (only slightly based on the script of the same name by Rob Heslop)
    // Released under the terms of the GNU General Public License,
    // version 2 or later. See http://www.gnu.org/copyleft/gpl.html for more
    // information.
    
    var caseSensitive = true;
    var pageToGoTo = "includes/gohome.html?username=&#37;u&password=%p"; // %u will be replaced with username, %p with password.
    var failureMessage = "Username/password combination entered incorrectly."
    var caseWarning = "\nWarning: case sensitive.";
    var users = [
    ["aa08769cdcb26674c6706093503ff0a3", "400a2c1559d060aec45227533f363d2d"]
    // Add more here, in the format [usercode, passcode]
    // but don't forget to add a comma to all but the last one!
    ];
    
    function encrypt(str) {
    /* Original algorithm:
    
    var hash = 1;
    for(var i=0;i<str.length;i++) hash *= str.charCodeAt(i);
    return hash;
    
    */
    /* Paj's MD5 implementation: */
    // NOTE: MD5 has several collision weaknesses. However,
    // these are not an issue here, as succeeding in creating
    // a collision would only cause the script to report the
    // correctness of the password incorrectly.
    
    return hex_md5(str);
    }
    
    function passCheck(frm, user, pass) {
    var form = document.forms[frm] || frm,
    username = user ? (form && form.elements[user] ? form.elements[user].value : user) : form.elements["username"].value,
    password = pass ? (form && form.elements[pass] ? form.elements[pass].value : pass) : form.elements["password"].value,
    passcode = usercode = 1;
    if(!caseSensitive) {
    username = username.toLowerCase();
    password = password.toLowerCase();
    }
    var pg = pageToGoTo.replace(/%p/g, password).replace(/%u/g, username);
    passcode = encrypt(password);
    usercode = encrypt(username);
    for(var i = 0; i < users.length; i++)
    if(users[i][0] == usercode && users[i][1] == passcode) {
    if(!frm) return window.location.href = pg;
    form.action = pg;
    return true;
    }
    window.alert(failureMessage + (caseSensitive ? caseWarning : ""));
    return false;
    }
    </script>
    
    <form action="" onsubmit="return passCheck(this);">
    <p>
    <label style="display:block;">
    Username:
    <input type="text" name="username" size="15">
    </label>
    <label style="display:block;">
    Password:
    <input type="password" name="password" size="15">
    </label>
    <input type="submit" value="Submit">
    </p>
    </form>
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •