Recently, a couple of students have asked me the same question:
“I need to authenticate users (other students) in my diploma thesis application with their faculty credentials. Is there a way to do this?”
The faculty student server (i.e. www.scs.ubbcluj.ro) offers two public services: IMAP (on TCP port 993) and SMTP (on TCP port 465). You can use either of these two services to authenticate a user. Just be sure you have the JavaMail jar in your classpath. Since April 2017 the JavaMail API is available as an open source project on GitHub.
Here is a sample piece of code, just pass the username and the password as command line parameters.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import java.util.Properties; import javax.mail.internet.*; import javax.mail.*; public class JavaMailAuthentication { public static void main(String[] args) throws Exception { String host = "example.com"; // replace example.com with your own host Properties props = System.getProperties(); props.put("mail.store.protocol", "imaps"); props.put("mail.imaps.port", 993); props.put("mail.imaps.host", host); javax.mail.Session mailSession = javax.mail.Session.getInstance(props, null); Store store = mailSession.getStore(); try { store.connect(host, 993, args[0], args[1]); System.out.println("Password is ok"); } catch (Exception e) { System.out.println("Password is not ok"); } } } |