如何检查特定用户名或密码是否正确或授权后是否创建会话

时间:2016-08-07 08:47:54

标签: java

如何检查特定用户名或密码是否正确,或者在获得授权后创建会话?

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        final String uid=jTextField1.getText();
        String pass = new String(jPasswordField1.getPassword());

        //server Config
        Properties prop=new Properties();
        prop.put("mail.smtp.auth","true");
        prop.put("mail.smtp.starttls.enable","true");
        prop.put("mail.smtp.host","smtp.gmail.com");   
        prop.put("mail.smtp.port","587");

        //client Authentication
        Authenticator auth=new Authenticator()
        {
          protected PasswordAuthentication getPasswordAuthentication()
        {
          return new PasswordAuthentication(uid,pass);
        }
        };

        //Session Creation
        Session session= Session.getInstance(prop,auth);

    try{
        String to=JOptionPane.showInputDialog("To :");
        String sub=JOptionPane.showInputDialog("Subject :");
        String data=JOptionPane.showInputDialog("Compose :"); 

        //Message Creation
        Message msg=new MimeMessage(session);
        msg.setFrom(new InternetAddress(uid));
  msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to));
        msg.setSubject(sub);
        msg.setText(data);
        //sending msg
        Transport.send(msg);
        JOptionPane.showMessageDialog(null,"sent !");

        // TODO add your handling code here:
         } catch (MessagingException ex) {
        Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
    }
}                 

1 个答案:

答案 0 :(得分:0)

select t.*
from (select t.*,
             row_number() over (partition by name order by entry_date desc) as seqnum
      from t
     ) t
where seqnum = 1;

尝试这个..... connect尝试使用给定的用户名和密码与服务器建立连接。 如果无法建立连接,则返回异常 将您的无效用户名/密码代码放入catch块。