Reputation: 307
Hey guys here I have a problem..In my java application there is a Login form. In that there is an option "forgot password..?" I want to send the password of the user from that..In that case the email address of the user identify with the user name give..no problem on that.But the problem is passwords are encrypted..How can I get those pwd to default format and send it. My login tabel name is Login and 3 field un,pw,type(admin or limit)..my mail send code is as follows..
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 );
}
Upvotes: 2
Views: 1798
Reputation: 201477
Passwords are usually not stored in an encrypted form, but rather in the form of the result of applying a secure one way hash function; best practices also include using a user (or at least system) specific salt to prevent attacks using rainbow tables. All of that said, you should probably just set a new (calculable) password for the user and then communicate to them that it is now set to that (e.g. read an employee table, use the last six digits of their ssn and their street address number).
Upvotes: 3