I am trying to compare a string from EditText fields to strings in shared preferences. If the strings match a new activity starts. The string in Sharedpreferenced is encoded with Base64. I am trying to compare the edit text string to the sharedpreferences string after it has been decoded but am unable to get the coding correct. how can I code this properly. examples are appreciated. my comparator is on line 77 and 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. }
There are 2 copies of
decryptedUseranddecryptedPasseach. One pair inside the try blocks and another pair as members. They are always empty at line 77 because you assign the decrypted values to different variables (lines 56 and 66) that you never use. Move the whole code into a single try block.