I have developed a restful service using C# .net,by using this service i have to validate the user login and password through android app developed in android studio.Now the password can contain special characters and in my case password is abc123* and URL become like this http://srvcallnimbus.azurewebsites.net/srvcallnimbus.svc/validateuserByCompanyName/testPhone/test@test.biz/abc123 But this does not pass to the service correctly and my android app return error.I have tried all answers at stockoverflow.But abc123 dows not get into encoded form.URLEncoder.Encode(password) does not encode the * character.
Asked
Active
Viewed 294 times
0
-
1Possible duplicate of [URL encoding in Android](https://stackoverflow.com/questions/3286067/url-encoding-in-android) – Torben Sep 03 '18 at 06:35
-
1Aside from the question likely being a duplicate, you should never pass sensitive data in the URL because the URL is most likely going to be logged somewhere and then you have log files full of plaintext passwords. – Torben Sep 03 '18 at 06:37
-
above provided solution does not work for me.i have tried URLEncoder.encode but it does not encode my password that is abc123* @Torben – Fatima jabbar Sep 03 '18 at 07:21
-
It looks like you are trying to implement your own authentication method (is that what you mean with login and password validation). You should instead use one of the existing and well known *REST authentication methods* (those are the Google keywords). You're also transporting passwords in the URL in plaintext using HTTP instead of HTTPS. You may be heading to a "rocky path" and should probably study the fundamentals of RESTful APs a bit more. – Torben Sep 03 '18 at 07:33
-
Thanx @Torben.. – Fatima jabbar Sep 04 '18 at 07:36
1 Answers
0
I found a solution as follow
Following steps involve to solve above mentioned problem
- Encode Your password in android app.
- Decode your password in WCF restful service.
Encode Password in Android App. Use the following method to encode your password in android app(encoding in base 64)
String base64Pass=""
string password="abc123*"
byte byteData[] =password.getBytes();
base64Pass= Base64.encodeToString(byteData, Base64.NO_WRAP);
Decode password in WCF restful service Use the following way to decode your password in WCF Restful service.
String data = password; //passed as parameter
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(data);
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char); //Decoded String

Fatima jabbar
- 1
- 1