나는 사용자가 애플리케이션에서 먼저 로그인해야하는 프로젝트에서 작업하고 있습니다. 그리고 내 작은 문제는 사용자가 자신의 사용자 이름과 암호를 입력 할 때 암호를 해시하고 사용자가 입력 한 사용자 이름과 암호 대신 서버에 보내야한다는 것입니다. 그래서 지금은 다음과 같이하고 있습니다.해시 된 사용자 이름과 비밀번호가있는 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;
}
그리고 여전히 사용자 이름과 비밀번호가 잘못되었다고 알려줍니다. 이미 해싱을 시도했기 때문에 해싱이 정확하다고 확신합니다. 그래서 아무도 내 실수가 어디인지 알 수 있습니까? 처음에는
그것은 작동합니다! 도움을 많이 주셔서 감사합니다! –