我正在嘗試將加密密碼存儲(chǔ)在我的應(yīng)用程序的 SharedPreferences 中。根據(jù)日志密碼正確保存并在加密后匹配鍵入的密碼,但在比較中它們不相等。每次它運(yùn)行 else 指令時(shí)。我找不到問(wèn)題所在,所以我尋求幫助!順便說(shuō)一句,有什么更好、更安全的密碼存儲(chǔ)方式,甚至是加密的?public class LoginActivity extends AppCompatActivity { private static final String PREFERENCES_NAME = "passHashed"; private static final String PREFERENCES_TEXT_FIELD = "textField"; public EditText Password; public TextView Info; private String passSavedHash; private SharedPreferences preferences; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); Password = (EditText) findViewById(R.id.etPassword); Info = (TextView) findViewById(R.id.Info); Button loginBtn = findViewById(R.id.loginButton); preferences = getSharedPreferences(PREFERENCES_NAME, AppCompatActivity.MODE_PRIVATE); if(!passRead().equals("0")) { passSavedHash = passRead(); Log.d("Password", "passHashed: " + passSavedHash); } else{ loginBtn.setText(R.string.set_pass); } } public void onClickValidate(View view) throws Exception { String password = Password.getText().toString(); String passHash = CipherAlgorithm.encrypt(password); Log.d("Password", "passHashed: " + passSavedHash); Log.d("Password", "passSavedHash: " + passHash); if(passRead().equals("0") && password.length() > 3) { passSave(); Intent intent = new Intent(LoginActivity.this, MainActivity.class); startActivity(intent); } else { if (Objects.equals(passSavedHash, passHash)) { Intent intent = new Intent(LoginActivity.this, MainActivity.class); startActivity(intent); } else { Info.setText(R.string.wron_pass); } } Password.setText(""); }
添加回答
舉報(bào)
0/150
提交
取消