...

View Full Version : I need to know how to validate password field after it exceeds the max limit



suvarna.mondal
05-30-2012, 08:13 AM
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??:(

felgall
05-30-2012, 08:16 AM
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.

suvarna.mondal
05-30-2012, 09:26 AM
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

felgall
05-30-2012, 09:41 AM
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..
http://javascriptexample.net/inc/alert.gif

Philip M
05-30-2012, 01:25 PM
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).


<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>

Philip M
05-30-2012, 02:52 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum