Something does not work out for me to encode one variable, tell me how to do it.

public class LoginPage extends Activity { public static final String Login = "login"; public static final String Password = "password"; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.efrgtaw); inal EditText loginIn = (EditText) findViewById(R.id.editText2); final EditText password = (EditText) findViewById(R.id.editText3); Button butlogin = (Button) findViewById(R.id.button1); butlogin.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getBaseContext(),"Please wait, connecting to server.", Toast.LENGTH_LONG).show(); try { String loginValue = URLEncoder.encode(loginIn.getText().toString(), "UTF-8"); String passwordStr = URLEncoder.encode(password.getText().toString(), "UTF-8"); HttpClient Client = new DefaultHttpClient(); String URL = "http://" + accountValue + ".megaplan.ru/BumsCommonApiV01/User/authorize.api/"+ loginValue + passwordStr + ""; Log.i("httpget", URL); try { String SetServerString = ""; HttpGet httpget = new HttpGet(URL); ResponseHandler<String> responseHandler = new BasicResponseHandler(); SetServerString = Client.execute(httpget,responseHandler); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally {} } catch (UnsupportedEncodingException e) { e.printStackTrace(); } finally {}}});}} 

I want to pass the password in the form of md5. Just password, login not to touch.

This option did not want to work:

 MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); digest.update(Password.getBytes()); byte messageDigest[] = digest.digest(); StringBuffer MD5Hash = new StringBuffer(); for (int i = 0; i < messageDigest.length; i++){ String h = Integer.toHexString(0xFF & messageDigest[i]); while (h.length() < 2) h = "0" + h; MD5Hash.append(h);} 
  • > This option did not want to work However, it is quite true. And in general, explain what it means "did not want to work"? - falstaf pm
  • It does not encode my password, and is transmitted to the server with a clean view (Maybe this is the piece of code I don’t put in there? (( - Imire
  • one
    In the above code, I do not see hashing, as I received the passwordStr from EditText , and send it, in its pure form. - falstaf
  • Thanks for the tip))) I didn’t notice something like that))) - Imire

1 answer 1

The error was that I incorrectly transmitted data. After correction, the password was encoded and transmitted as expected.