2013-11-24 181 views
2

嘿家伙在这里我有一个问题..在我的Java应用程序中有一个登录表单。在那里有一个选项“忘记密码..?”我想从那发送用户的密码..在这种情况下,用户的电子邮件地址标识用户名give..no that.But问题是密码加密..我怎么能得到那些密码以默认格式发送。我的登录名TABEL是登录和3场未私服,类型..我的邮件发送代码如下(admin或限制)..通过电子邮件发送密码

try{ 

    Properties props = new Properties(); 
    props.put("mail.smtp.host", "smtp.gmail.com"); // for gmail use smtp.gmail.com 
    props.put("mail.smtp.auth", "true"); 
    props.put("mail.debug", "true"); 
    props.put("mail.smtp.starttls.enable", "true"); 
    props.put("mail.smtp.port", "465"); 
    props.put("mail.smtp.socketFactory.port", "465"); 
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); 
    props.put("mail.smtp.socketFactory.fallback", "false"); 

    Session mailSession = Session.getInstance(props, new javax.mail.Authenticator() { 

     protected PasswordAuthentication getPasswordAuthentication() { 
      return new PasswordAuthentication("[email protected]", "password"); 
     } 
    }); 

    mailSession.setDebug(true); // Enable the debug mode 

    Message msg = new MimeMessage(mailSession); 

    //--[ Set the FROM, TO, DATE and SUBJECT fields 
    msg.setFrom(new InternetAddress("[email protected]")); 
    msg.setRecipients( Message.RecipientType.TO,InternetAddress.parse("[email protected]")); 
    msg.setSentDate(new Date(232323)); 
    msg.setSubject("Hello World!"); 

    //--[ Create the body of the mail 
    msg.setText("Hello from my first e-mail sent with JavaMail"); 

    //--[ Ask the Transport class to send our mail message 
    Transport.send(msg); 

}catch(Exception E){ 
    System.out.println("Oops something has gone pearshaped!"); 
    System.out.println(E); 
} 
+7

**不要以纯文本**存储密码。可逆加密(几乎)不会更好。你需要理解哈希的含义。 – SLaks

+0

密码是加密密码还是哈希密码?加密密码需要使用正确的密钥进行解密。如果密码被散列,那么您将无法向用户发送他们的密码。相反,您必须要求用户创建一个新密码。 – Max

+6

安全性**很难**。不要重新发明轮子。使用现有的,经过验证的认证软件包。 – SLaks

回答

3

密码通常不存储在加密的形式,而是在申请secure one way hash function的结果形式;最佳做法还包括使用用户(或至少系统)特定salt以防止使用rainbow tables进行攻击。所有这些说,你应该为用户设置一个新的(可计算的)密码,然后告诉他们现在已经设置了这个密码(例如,阅读员工表,使用他们的ssn的最后六位数字和他们的街道地址数)。