简体   繁体   中英

how to encode password in javascript?

I have password textbox which allows the user to enter any type of characters with the password. But registration fails when the user uses a password like say 'mypass@676/my&pass/my%pass' but when other characters are used he is able to register. Is it due to password not getting encoded in the front end?

I posting the registration url to my register service since it is a url if the password is mypass@676 the system takes only upto mypass and ommits the other characters and as a result it is failing.

My code in javascript is like this,

data+= "&password="+$(formID).find('input[id=password]').val(); and this will go to my service as it is.

Issues:

  1. If i encode my password in javascript say my password is "my%passw" so when i encode "my%25pass" and during login which i should give?

  2. Ok if i encode again during login what will happen to my existing users passwords will it get encoded?

Use encodeURIComponent() :

data += "&password=" + encodeURIComponent($(formID).find('input[id=password]').val());

By the way, input[id=password] can be simplified to input#password .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM