2011-09-28 5 views
0

나는 사용자가 애플리케이션에서 먼저 로그인해야하는 프로젝트에서 작업하고 있습니다. 그리고 내 작은 문제는 사용자가 자신의 사용자 이름과 암호를 입력 할 때 암호를 해시하고 사용자가 입력 한 사용자 이름과 암호 대신 서버에 보내야한다는 것입니다. 그래서 지금은 다음과 같이하고 있습니다.해시 된 사용자 이름과 비밀번호가있는 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; 
} 

그리고 여전히 사용자 이름과 비밀번호가 잘못되었다고 알려줍니다. 이미 해싱을 시도했기 때문에 해싱이 정확하다고 확신합니다. 그래서 아무도 내 실수가 어디인지 알 수 있습니까? 처음에는

답변

0

경우에, 나는 어쩌면 생각을 이벤트의 종류. 나는 당신이 버튼 로그인을 가지고 있다고 생각한다. 그래서 onClick 메쏘드에이 매개 변수들을 설정하면 효과가 있다고 생각한다.

+0

그것은 작동합니다! 도움을 많이 주셔서 감사합니다! –

1

, 당신의 해시 사용자 이름과 해시 된 암호는 동일합니다 :

암호와 사용자 이름의 해시 해시와 서버는 사용자 이름과 암호를 각각, 나는이 추측하고있어 어디
public String hashUser(String username, String password) throws NoSuchAlgorithmException, UnsupportedEncodingException{ 
    String hashUser = SHA1.Sha1Hash(username); 
    String hashPass = SHA1.Sha1Hash(password); 
    String luser = hashPass+hashUser; // <-- Hashed pass + user 
    String lastUser = SHA1.Sha1Hash(luser); // <-- Hashed a second time 
    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; // <-- Hashed pass + user 
    String lastPass = SHA1.Sha1Hash(lpass); // <-- Hashed a second time 
    return lastPass; 
} 

하지 않는 한 문제가 있습니다.

단지 같은 것을 사용하지 이유 : 문제가 edittext에서 사용자 이름과 암호를 얻기에 .Try 일부에

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()))); 

을 넣어 모든 것이 괜찮

postParameters.add(new BasicNameValuePair("username_hash", SHA1.Sha1Hash(txtUserName.getText().toString()))); 
postParameters.add(new BasicNameValuePair("password_hash", SHA1.Sha1Hash(txtPassword.getText().toString()))); 
+0

내 실수, 사용자 이름 및 비밀번호가 같지 않습니다. 여기에 코드를 복사하여 붙여 넣을 때 실수를 저질렀습니다. –

관련 문제