Results 1 to 5 of 5

Thread: Variation on Encryted Password script

  1. #1
    Join Date
    Jul 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Variation on Encryted Password script

    Hello,

    I am using DD's Encrypted password script and it works fine UNTIL I change the form submit from a button:

    <input type="button" value="Submit" onClick="submitentry()"></form>

    to an image:

    <input type="image" src="i/enter.gif" onClick="submitentry()"></form>

    How can I use an image button with this script: http://www.dynamicdrive.com/dynamicindex9/password.htm

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

    Default

    I don't think much of this script.
    Code:
    <script type="text/javascript">
    // Encrypted Password script - by Twey
    // (only slightly based on the script of the same name by Rob Heslop)
    // Script featured on Dynamic Drive 
    // Visit http://www.dynamicdrive.com/
    
    // User-editable vars.
    
    var caseSensitive = false;
    var pageToGoTo = "%p.html"; // %u for username, %p for password.
    var failureMessage = "Username/password combination entered incorrectly."
    var caseWarning = "\nWarning: case sensitive.";
    var users = [
      [168698684, 143676400]
      // Add more here, in the format [usercode, passcode]
      // but don't forget to add a comma to all but the last one!
    ];
    
    // End of user-editable vars.
    
    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);
      for(var i = 0; i < password.length || i < username.length; i++) {
        if(i < password.length) passcode *= password.charCodeAt(i);
        if(i < username.length) usercode *= username.charCodeAt(i);
      }
      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>
    Code:
    <form action="" onsubmit="return passCheck(this);">
      <input type="text" name="username" size="15">
      <label>
        Password:
        <input type="password" name="password" size="15">
      </label>
      <input type="submit" value="Submit">
    </form>
    The case sensitivity requires that you use a new calculation function if you want a case-sensitive username and password:
    Code:
    function calculate(user, pass, caseSens) {
      var username = caseSens ? user : user.toLowerCase(),
        password = caseSens ? pass : pass.toLowerCase(),
        usercode = passcode = 1;
      for(i = 0; i < password.length || i < username.length; i++) {
        if(i < password.length) passcode *= password.charCodeAt(i);
        if(i < username.length) usercode *= username.charCodeAt(i);
      }
      return [usercode, passcode];
    }
    If you don't know what to do with that, ignore it and leave caseSensitive as false.

    This script should handle image inputs just as easily as standard submit buttons. It also allows submission of the form in other ways, such as by pressing enter.
    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!

  3. #3
    Join Date
    Jul 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks! A couple questions:

    Quote Originally Posted by Twey
    I don't think much of this script....
    I relpaced the 168698684, 143676400 with the values generated for my login and when I press submit I get a blank white page. Is there more to the configuration? As well, will your script allow me to substitute <input type="image" src="i/enter.gif"> for <input type="submit" value="Submit">? I really need to use an image in place of the Submit button.

  4. #4
    Join Date
    Jul 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    [QUOTE=Twey] TweyQUOTE]

    Sorry...I figured out how you wanted it configured. It works great with the image button, too. Thanks again!

  5. #5
    Join Date
    Dec 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    The Script is gr8 !!
    It helped me alot thanks for it....


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
  •