通过电子邮件发送密码

时间:2013-11-24 04:04:02

标签: java netbeans

嘿伙计们,我有一个问题..在我的java应用程序中有一个Login表单。在那里有一个选项“忘记密码..?”我想从那里发送用户的密码..在这种情况下,用户的电子邮件地址标识用户名给出..没有问题。但问题是密码是加密的..我怎么能得到那些密码默认格式并发送。我的登录表名是Login和3字段un,pw,type(admin或limit)..我的邮件发送代码如下..

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("ravinduis34@gmail.com",    "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( "ravinduis34@gmail.com" ) );
    msg.setRecipients(    Message.RecipientType.TO,InternetAddress.parse("ravindusisira@gmail.com") );
    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 );
}

1 个答案:

答案 0 :(得分:3)

密码通常不以加密形式存储,而是以应用secure one way hash function的结果形式存储;最佳做法还包括使用特定salt的用户(或至少是系统)来阻止使用rainbow tables的攻击。所有这些都说,您可能只需为用户设置一个新的(可计算的)密码,然后与他们沟通它现在设置为该密码(例如,阅读员工表,使用他们的ssn的最后六位数及其街道地址数)。