0

EditTextフィールドの文字列を共有設定の文字列と比較しようとしています。文字列が一致すると、新しいアクティビティが開始されます。Sharedpreferencedの文字列は、Base64でエンコードされています。デコードされた後、編集テキスト文字列を共有設定文字列と比較しようとしていますが、コーディングを正しく行うことができません。これを正しくコーディングするにはどうすればよいですか。例をいただければ幸いです。私のコンパレータは77行目と78行目にあります

 44. public void onClick(View arg0) {
 45.    
 46.   sp=this.getSharedPreferences("AccessApp", MODE_WORLD_READABLE);
 47.  
 48.   
 49.   
 50.   
 51.   byte[] key = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5 };
 52.   
 53.   
 54.   try {
 55.    user = sp.getString("USERNAME_KEY", null);
 56.        String decryptedUser = decrypt(user, key);  
 57.        
 58.         
 59.   }
 60.  catch (Exception e) {
 61.   // TODO Auto-generated catch block
 62.   e.printStackTrace();
 63.  }   
 64.  try {
 65.       pass = sp.getString("PASSWORD_KEY", null);
 66.       String decryptedPass = decrypt(pass, key);  
 67.       
 68.        
 69.
 70. } catch (Exception e) {
 71.   // TODO Auto-generated catch block
 72.   e.printStackTrace();
 73. }
 74.  
 75.  if(lBttn.equals(arg0)){
 76.    
 77.     if((uname.getText().toString().equals(decryptedUser))  && 
 78.       (pword.getText().toString().equals(decryptedPass)))
 79.      
 80.           {
 81.         Toast.makeText(this, "You are Logged In", 20000).show();
 82.                
 83.              Intent intent;
 84.               intent=new Intent(this,details.class);
 85.               startActivity(intent);
 86.             flag=1;
 87.           }
4

1 に答える 1

8

とのコピーが2つありdecryptedUser ますdecryptedPass。tryブロック内の1つのペアと、メンバーとしての別のペア。復号化された値を使用しないさまざまな変数(56行目と66行目)に割り当てるため、77行目では常に空になっています。コード全体を単一のtryブロックに移動します。

public void onClick(View arg0) {
    ...
    ...
    String decryptedUser;
    String decryptedPass;
    try {
        user = sp.getString("USERNAME_KEY", null);
        decryptedUser = decrypt(user, key);  
        pass = sp.getString("PASSWORD_KEY", null);
        decryptedPass = decrypt(pass, key);
        /* Your if statements follow from here */
        ...
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }   

}
于 2012-12-03T13:20:16.097 に答える