use*_*694 0 java authentication base64 android login
我试图将EditText字段中的字符串与共享首选项中的字符串进行比较.如果字符串匹配,则启动新活动.Sharedpreferenced中的字符串使用Base64编码.我试图将编辑文本字符串与sharedpreferences字符串进行比较后解码但无法正确编码.我怎样才能正确编码.例子表示赞赏.我的比较器在第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. }
Run Code Online (Sandbox Code Playgroud)
有2份decryptedUser 和decryptedPass每个.try块中有一对,另一对是成员.它们在第77行始终为空,因为您将解密的值分配给您从不使用的不同变量(第56和66行).将整个代码移动到一个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();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
418 次 |
| 最近记录: |