简体   繁体   English

如何在javascript中编码密码?

[英]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. 但是,当用户使用诸​​如“ mypass @ 676 / my&pass / my%pass”之类的密码时,注册失败,但是当使用其他字符时,他可以注册。 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. 我将注册网址发布到我的注册服务中,因为如果密码为mypass @ 676,则它是一个网址,系统仅占用mypass的权限,而忽略其他字符,因此失败。

My code in javascript is like this, 我在javascript中的代码是这样的,

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? 如果我使用javascript对密码进行编码,则说我的密码是“ my%passw”,那么当我对“ my%25pass”进行编码并且在登录期间我应该给我什么?

  2. Ok if i encode again during login what will happen to my existing users passwords will it get encoded? 好吧,如果我在登录时再次进行编码,那么现有用户密码将如何编码?

Use encodeURIComponent() : 使用encodeURIComponent()

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

By the way, input[id=password] can be simplified to input#password . 顺便说一句, input[id=password]可以简化为input#password

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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