Javamail传输成功使用无效凭证进行身份验证 [英] Javamail transport getting success to authenticate with invalid credentials

查看:61
本文介绍了Javamail传输成功使用无效凭证进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码来验证电子邮件和密码.如果我使用有效的凭据,则在我运行该应用程序后,它将立即进行身份验证.但是,如果我注销并尝试使用一些无效的凭据再次登录,它将继续获得成功的身份验证,并且不会引发异常.似乎传输保留了先前的数据(有效凭据)进行缓存,并在我再次登录时使用它.我检查了一下,变量"email"和"password"没有问题.当我先尝试一些无效的凭据,然后再尝试一些有效的凭据时,情况恰恰相反.你们对发生的事情有任何想法吗?

I have this code to authenticate the e-mail and password. If I use valid credentials, as soon as I run the app, it authenticates. But if I logout and try to login again with some invalid credential, it continues to getting success to authenticate and no Exception is risen. It seems like the Transport is keeping the previously data (the valid credentials) cached and using it when I login again. I checked and there's no problem with the variables "email" and "password". The opposite happens when I try some invalid credentials first and some valid one later. Do you guys have any idea about what is happening?

这是发生代码的地方:

谢谢!

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();

}

推荐答案

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆