I am having a wired issue in my AngularJs application. When user is trying to login to the app and if the password contains ampersand (&), then it couldn’t able to validate the user.
I am using OWIN, oAuth2.0 JWT token to validate my Asp.Net Web APIs.
When i debug i found that if the password contains ampersand (&), then it is truncating all the characters from ampersand (&).
For example, if the password is ‘x&x’ the OAuthValidateClientAuthenticationContext context is getting only ‘x’ in password value.
I have attached a screen shot of the issue click to see the issue..
Any help on this issue, would be highly appreciated.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Am guessing the value is being interpreted as a query string separator.
Try using the javascript method
encodeURI()
Or
EncodeURIcomponent()
On your password value before posting to the server, so the ampersand becomes
&
The server will decode this for you.
You’ll probably find that slashes and question marks will also not work in passwords if you dont
Method 2
I had the same issue with an anguar project while entering special characters(ex: &, +) in password field. Encoding password with encodeURIComponent did the trick:
“&password=” + encodeURIComponent(password)
Hope it helps
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0