Click here to Skip to main content
15,888,039 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Below code is in java :

private static final int PASSWORD_MAX_CONS_LENGTH = 3;
for (int i = 0; i < oldPassword.length() - PASSWORD_MAX_CONS_LENGTH + 1; i++) {
if (passwordString.indexOf(oldPassword.substring(i, i
+ PASSWORD_MAX_CONS_LENGTH)) >= 0)

Now we want the same validation in java script ?

How can I compare the same in java script.

Here, we are checking if old password and new password consecutive character is greater than 3 then should throw error.

Same thing I want in java script:

If old password and new password consecutive characters are greater than 3 then it should show some error.

What I have tried:

var PASSWORD_MAX_CONS_LENGTH = 3;
if (oldPassword != null) {
if (oldPassword.length() - PASSWORD_MAX_CONS_LENGTH ) {
if (userpassword.indexOf(oldPassword)...
Posted
Comments
Member 12539934 7-Jun-16 2:41am    
I tried this but it is not working :

function checkPasswordValue(username, userpassword,oldPassword) { var old_password = document.getElementsByName("OldPassword"); var old_password_value= old_password[0].value; if (old_password_value != null) { if (userpassword.indexOf(old_password_value.match((/^\/{3}/)) >= 0) { return false; } return true; } }
Sergey Alexandrovich Kryukov 7-Jun-16 3:09am    
Why any password manipulations on client side? It it for a Web site or what?
—SA
Member 12539934 7-Jun-16 3:31am    
All validations we are changing from java to java script(client side)
Sergey Alexandrovich Kryukov 7-Jun-16 3:34am    
There is no such thing as "Java script".
You should never even store passwords anywhere, forget about client-side validation, which can be easily worked around; not just easily, but in no time. So easy that it makes password protection pointless.
Storing passwords is never needed for authentication. Normally, cryptographic hash functions are used.
—SA
Mohibur Rashid 7-Jun-16 4:51am    
So, if some user modify the javascript code and validate anything... what would happen?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900