我正在开发一个项目,用户必须首先在应用程序中登录才能使用它。而我的小问题是,当用户输入他的用户名和密码时,我必须将它们散列并发送到服务器,而不是用户输入的用户名和密码。所以现在我在做这样的事情:使用哈希用户名和密码的Android登录
EditText txtUserName = (EditText) findViewById (R.id.username_login_input);
EditText txtPassword = (EditText) findViewById (R.id.password_login_input);
HttpClient httpclient;
HttpPost httppost;
ArrayList<NameValuePair> postParameters;
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://www.rpc.shalqlqlq.com");
postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("username_hash", hashUser(txtUserName.getText().toString(),txtPassword.getText().toString())));
postParameters.add(new BasicNameValuePair("password_hash", hashPass(txtUserName.getText().toString(),txtPassword.getText().toString())));
httppost.setEntity(new UrlEncodedFormEntity(postParameters));
HttpResponse response = httpclient.execute(httppost);
Log.w("Response ","Status line : "+ response.getStatusLine().toString());
byte[] buffer = new byte[1024];
buffer = EntityUtils.toString(response.getEntity()).getBytes();
public String hashUser(String username, String password) throws NoSuchAlgorithmException, UnsupportedEncodingException{
String hashUser = SHA1.Sha1Hash(username);
String hashPass = SHA1.Sha1Hash(password);
String luser = hashPass+hashUser;
String lastUser = SHA1.Sha1Hash(luser);
return lastUser;
}
public String hashPass(String username, String password) throws NoSuchAlgorithmException, UnsupportedEncodingException{
String hashUser = SHA1.Sha1Hash(username);
String hashPass = SHA1.Sha1Hash(password);
String lpass = hashPass+hashUser;
String lastPass = SHA1.Sha1Hash(lpass);
return lastPass;
}
它仍然告诉我,用户名和密码不正确。我很确定哈希是正确的,因为我已经尝试过了。那么任何人都可以帮助我找出我的错误在哪里?
它的工作原理!非常感谢您的帮助! –