Javamail传输获得成功以无效凭据进行身份验证
问题描述:
我有此代码来验证电子邮件和密码。如果我使用有效凭证,只要我运行该应用程序,它就会进行身份验证。但是,如果我注销并尝试使用某些无效凭证重新登录,它将继续获得成功进行身份验证,并且不会出现异常。看起来Transport正在保存先前的数据(有效凭证),并在我再次登录时使用它。我检查了变量“email”和“password”没有问题。当我先尝试一些无效凭证并稍后再尝试一些无效凭证时,会发生相反情况你们有什么想法发生了什么?Javamail传输获得成功以无效凭据进行身份验证
这是它发生的代码片段:
谢谢!
public void check_user(final String email, final String password){
final ProgressDialog pb = new ProgressDialog(this);
pb.setIndeterminate(true);
pb.setTitle("Verificando usuário");
pb.setMessage("Por favor, aguarde...");
pb.setCancelable(false);
pb.show();
Thread t = new Thread(new Runnable() {
@Override
public void run() {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.office365.com");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "587");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
//Authenticating the password
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(email, password);
}
});
try {
transport = session.getTransport("smtp");
transport.connect(email, password);
transport.close();
} catch (Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(LoginActivity.this, "Usuário e/ou senha inválidos.", Toast.LENGTH_LONG).show();
pb.dismiss();
}
});
return;
}
SharedPreferences.Editor data = getSharedPreferences("user_data", 0).edit();
data.putString("username", email).commit();
data.putString("password", password).commit();
data.putBoolean("isLogged", true).commit();
runOnUiThread(new Runnable() {
@Override
public void run() {
get_in();
}
});
}
});
t.start();
}
太感谢你了,比尔!这解决了我的问题! –