问题描述
我正在使用GWT框架为我的公司开发一个ERP,我将获得
的未读电子邮件数量Java Mail API。
我可以这样做,但问题是我在
数据库上存储SHA-512散列密码,我不会将清除密码传递给Java Mail API,而只是使用散列密码避免在网络上传送清除密码。
我使用这段代码获取未读邮件的数量:
private static int getNumberOfUnreadMails(){
int numberOfUnreadMails = 0;
属性属性= new Properties();
properties.put(mail.imap.host,myserver.com);
properties.put(mail.imap.user,[email protected]);
properties.put(mail.imap.socketFactory,143);
properties.put(mail.imap.socketFactory.class,java.net.ssl.SSLSocketFactory);
properties.put(mail.imap.port,143);
会话session = Session.getDefaultInstance(属性,新的Authenticator(){
@Override
protected PasswordAuthentication getPasswordAuthentication(){
返回新的PasswordAuthentication([email protected] mypassword);
}
});
店铺;
try {
store = session.getStore(imap);
store.connect();
文件夹文件夹= store.getFolder(Inbox);
numberOfUnreadMails = folder.getUnreadMessageCount();
} catch(Exception e){
e.printStackTrace();
}
return numberOfUnreadMails;
}
我还可以使用另一个散列算法。
如果您知道我的问题的解决方案,请事先提醒您。
PS:抱歉我的英文不好,我是法国人。
您的IMAP服务器将需要unhashed密码才能进行身份验证。您可能已经在使用SSL(因为您设置了 mail.imap.socketFactory.class
),所以您的密码永远不会发送到明确的。
BTW:使用带有javamail的SSL的IMAP的正确方法是使用 imaps
协议(并使用邮件)。 imaps。*
,不使用imap协议并指定一个SSL套接字工厂作为套接字工厂。通常,带有SSL端口的IMAP也是993,而不是143。
Good morning everybody,
I'm developping an ERP for my company with the GWT Framework and I would getthe number of unread emails using the Java Mail API.I can do this but, the problem is I stores the SHA-512 hashed password on thedatabase and I would not pass the clear password to the Java Mail API, but just the hashed password to avoiding to transmit the clear password on the network.
I use this code to get the number of unread mail:
private static int getNumberOfUnreadMails() {
int numberOfUnreadMails = 0;
Properties properties = new Properties();
properties.put("mail.imap.host", "myserver.com");
properties.put("mail.imap.user", "[email protected]");
properties.put("mail.imap.socketFactory", 143);
properties.put("mail.imap.socketFactory.class", "java.net.ssl.SSLSocketFactory");
properties.put("mail.imap.port", 143);
Session session = Session.getDefaultInstance(properties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("[email protected]", "mypassword");
}
});
Store store;
try {
store = session.getStore("imap");
store.connect();
Folder folder = store.getFolder("Inbox");
numberOfUnreadMails = folder.getUnreadMessageCount();
} catch (Exception e) {
e.printStackTrace();
}
return numberOfUnreadMails;
}
I can also use another hashing algorithm.If you know a solution for my problem, thaks you in advance.
P.S.: Sorry for my poor English, I’m French.
Your IMAP-server will need the unhashed password to be able to authenticate. You probably are already using SSL (as you set mail.imap.socketFactory.class
), so your password is never sent in the clear.
BTW: the correct way to use IMAP with SSL with javamail is to use the imaps
protocol (and use the mail.imaps.*
, not using the imap protocol and specifying an SSL socket factory as the socket factory. Also usually the IMAP with SSL port is 993, not 143 .
这篇关于通过散列Java Mail API的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!