【问题标题】:Javamail transport getting success to authenticate with invalid credentialsJavamail 传输成功使用无效凭据进行身份验证
【发布时间】:2016-08-07 05:19:59
【问题描述】:

我有这个代码来验证电子邮件和密码。如果我使用有效的凭据,只要我运行该应用程序,它就会进行身份验证。但是,如果我注销并尝试使用一些无效的凭据再次登录,它会继续成功进行身份验证并且不会出现异常。似乎传输正在缓存以前的数据(有效凭据)并在我再次登录时使用它。我检查了变量“电子邮件”和“密码”没有问题。当我先尝试一些无效的凭据,然后再尝试一些有效的凭据时,会发生相反的情况。你们对正在发生的事情有任何想法吗?

这是发生它的一段代码:

谢谢!

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

}

【问题讨论】:

    标签: java android jakarta-mail


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2015-07-19
    • 2015-12-20
    • 2014-10-15
    • 1970-01-01
    • 2020-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多