Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I need to know how to validate password field after it exceeds the max limit

    hey i just to know,
    In password field, when user press any key after it exceeds the max.length den he/she should get an alert.
    bt wen he/she clicks a backspace key it should work.

    The all i mean to say is ..... there should be any onkeypress event, when user press a key after exceeding max limit, the alert should occur bt when backspace is being pressed then the event should not occur.. can anyone help me with the code??

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by suvarna.mondal View Post
    hey i just to know,
    In password field, when user press any key after it exceeds the max.length den he/she should get an alert.
    bt wen he/she clicks a backspace key it should work.

    The all i mean to say is ..... there should be any onkeypress event, when user press a key after exceeding max limit, the alert should occur bt when backspace is being pressed then the event should not occur.. can anyone help me with the code??
    Maximum lengths can be specified in the HTML

    <input type="password" maxlength="50000">

    if you really need to set a maximum - since most systems save a hash of the password rather than the password itself and the hash is always the same length no matter how long the password is.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New to the CF scene
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    Maximum lengths can be specified in the HTML

    <input type="password" maxlength="50000">

    if you really need to set a maximum - since most systems save a hash of the password rather than the password itself and the hash is always the same length no matter how long the password is.
    no that i know....bt after crossing 50000, if we try to press any other key, we won't get an alert for that....I need code for that

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by suvarna.mondal View Post
    no that i know....bt after crossing 50000, if we try to press any other key, we won't get an alert for that....I need code for that
    If you use an MD5 hash then a trillion character password will only use 16 characters in your database.

    If you use a SHA1 hash then a quintillion character password will only use 20 characters in your database.

    If you use a SHA256 hash then a googolplex character password (which would take billions of years to type in once) would use 64 characters in your database.

    A one character password would also take 16, 20, or 64 characters in the database using the same hashes.

    Since you should NEVER store passwords in the database in plain text the length that people should be allowed to enter should only be limited by the amount of time the universe continues to exist for since if they started with a trillion people typing parts of their password for them when the universe began and those trillion people finish typing the password for them just as the universe ends then a SHA256 hash of the password will still only take 64 characters.

    Anyway the JavaScript alert is only useful for debugging as in some browsers you can use it to turn off JavaScript completely for the web page..
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,082
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by suvarna.mondal View Post
    no that i know....bt after crossing 50000, if we try to press any other key, we won't get an alert for that....I need code for that
    The user cannot enter more than the maximum number of characters (maxlength = "12"), so no warning can be given (except that 12 characters has been reached so the user cannnot enter any more).

    Code:
    <input type = "password" id = "pwdbox" size = "12" maxlengh = "12" onkeyup = "countChars()">
    <span id = "message" style="color:red"></span>
    <script type = "text/javascript">
    
    function countChars() {
    var max = 12;
    document.getElementById("message").innerHTML = "";
    var msg = "You have now entered the maximum number of characters allowed - " + max;
    var len = document.getElementById("pwdbox").value.length;
    if (len >= max) {
    document.getElementById("message").innerHTML = msg;
    }
    }
    
    </script>

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,082
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by iBall View Post
    If you use alert, for 1 thing, it won't work in browsers with javascript not available.
    No JavaScript will work in browsers where for whatever reason Javascript is not available. I would have thought that most people understood that.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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