KNA-11 OTP Generator
KNA-11 OTP Generator
11.Assignment Submission
Student Name: Praveen Biradar
ID: KODD8KS8I
https://drive.google.com/file/d/1vRMt6flw5Ba5BZwoxYT8RGT1KnR_P4e1/view?usp=drivesdk
https://drive.google.com/file/d/1JVF9O_hfwN0IyeTs2cFU7qpuWO4OUTpo/view?usp=drivesdk
Sir, we have completed the OTP Generator project using the required details. The application generates a
random OTP and sends it via email. To implement this, I used an app password from my email
(praveenbiradar163@gmail.com) for secure OTP transmission.
We have placed the config.properties file inside the resources folder in src to ensure proper access at runtime.
Both a Runnable JAR for direct execution and a normal JAR for use in other projects have been created. The
application is ready for use. Let us know if any modifications are needed.
For email functionality, I downloaded and used the following JAR files:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.Random;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public OTPEmailSender() {
loadConfig(); // Load email & password from config.properties
setTitle("OTP GENERATOR");
setSize(400, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(4, 1));
getContentPane().setBackground(new Color(173, 216, 230));
add(inputPanel);
add(buttonPanel);
add(statusLabel);
send4DigitOTPButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
sendOTP(4);
}
});
send6DigitOTPButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
sendOTP(6);
}
});
}
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(senderEmail));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient));
message.setSubject("Your OTP Code");
String otpMessage = otp + " is a " + digits + "-digit OTP sent to " + recipient + " by PRAVEEN BIRADAR (ID:
KODD8KS8I ). This OTP is valid for 5 minutes.";
message.setText(otpMessage);
Transport.send(message);
return true;
} catch (MessagingException e) {