reset
// save file as reset.java
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
import java.util.Random;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.swing.JOptionPane;
/**
*
* @author hp
*/
public class Reset extends javax.swing.JFrame {
/**
* Creates new form Reset
*/
public Reset() {
initComponents();
jPasswordField1.setVisible(false);
jButton1.setVisible(false);
jButton2.setVisible(false);
jTextField2.setVisible(false);
jLabel2.setVisible(false);
jLabel3.setVisible(false);
}
class BabyOfAuthenticator extends Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
// create object of PA
PasswordAuthentication pa = new PasswordAuthentication("kumarsambhav@srmscet.edu","bhushan15.721");
// return object of PA
return pa;
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jPasswordField1 = new javax.swing.JPasswordField();
jComboBox1 = new javax.swing.JComboBox<>();
jLabel4 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBounds(new java.awt.Rectangle(500, 200, 0, 0));
jLabel1.setText("Account No. : ");
jLabel2.setText("OTP : ");
jLabel3.setText("Password : ");
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "sbi", "pnb", "hdfc", "kotak" }));
jLabel4.setText("Bank : ");
jButton1.setText("Reset");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Check OTP");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("Send OTP");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(50, 50, 50)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addGap(32, 32, 32)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPasswordField1, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
.addComponent(jTextField2))
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(94, 94, 94)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)))
.addContainerGap(56, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(43, 43, 43)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton3))
.addContainerGap(89, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
String bank = (String) jComboBox1.getSelectedItem();
String acno = jTextField1.getText();
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sambhav", "root", "sam");
Statement stmt=con.createStatement();
//System.out.println(bank);
ResultSet rs=stmt.executeQuery("select mail,status from "+bank+" where ac_no='"+acno+"'");
//int deposit=0;
String email = null;
int status=0;
while(rs.next())
{
email=rs.getString("mail");
status=rs.getInt("status");
//deposit= rs.getInt("amount");
}
//if(status!=0)
{
Random random = new Random();
String id = String.format("%04d", random.nextInt(10000));
System.out.println("RAndon is ###########"+id);
Properties p = new Properties();
p.put("mail.smtp.host","smtp.gmail.com");
p.put("mail.smtp.port","587");
p.put("mail.smtp.starttls.enable","true");
p.put("mail.smtp.auth","true");
//p.put("mail.smtp.ssl.trust","smtp.gmail.com");
p.put("mail.debug","true");
// create object of Authenticator
BabyOfAuthenticator baby = new BabyOfAuthenticator();
// create object of session
Session ses = Session.getInstance(p, baby);
// create object of mime-message to denote
// actual message to be sent to mail server
MimeMessage message = new MimeMessage(ses);
// provide a subject
message.setSubject(" OTP ");
String[] emails = email.split(",");
InternetAddress[] inadrs = new InternetAddress[emails.length];
for(int i = 0; i < emails.length; i++)
{
// create object of internet-address to
// denote email
InternetAddress ina = new InternetAddress(emails[i]);
// store this object inside array
inadrs[i] = ina;
}
// lets specify the types of RCVRS
message.addRecipients(Message.RecipientType.TO, inadrs);
// create some body parts
MimeBodyPart body1 = new MimeBodyPart();//body2 = new MimeBodyPart(),body3 = new MimeBodyPart();
// associate a text with body1
body1.setContent("<p style='color : red;'>OTP to change Password <br>"+id+"</br></p>", "text/html");
//String path ="f:\\a.png";
//File f1 = new File("f:\\a.png");
//File f2 = new File("c:\\Users\\hp\\Downloads\\GUI02.txt");
// associate attachments with body2 and body3
//body2.attachFile(f1);
//body3.attachFile(f2);
// create multipart to store body parts
MimeMultipart parts = new MimeMultipart();
// store all the body parts inside multipart
parts.addBodyPart(body1);
//parts.addBodyPart(body2);
//parts.addBodyPart(body3);
// store multipart inside message
message.setContent(parts);
// send this message to the mail server
Transport.send(message);
System.out.println("OTP send");
String insertquery="update "+bank+" set otp="+id+" where ac_no='"+acno+"'";
PreparedStatement ps1=con.prepareStatement(insertquery);
ps1.executeUpdate();
jButton1.setVisible(false);
jButton2.setVisible(true);
jButton3.setVisible(false);
jComboBox1.setVisible(true);
jLabel1.setVisible(true);
jLabel2.setVisible(true);
jLabel3.setVisible(false);
jLabel4.setVisible(true);
jPasswordField1.setVisible(false);
jTextField1.setVisible(true);
jTextField2.setVisible(true);
}
}
catch(Exception e)
{
System.out.println(e);
}
}//GEN-LAST:event_jButton3ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
String bank = (String) jComboBox1.getSelectedItem();
String acno = jTextField1.getText();
String otpuser= jTextField2.getText();
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sambhav", "root", "sam");
Statement stmt=con.createStatement();
//System.out.println(bank);
ResultSet rs=stmt.executeQuery("select otp,status from "+bank+" where ac_no='"+acno+"'");
//int deposit=0;
String otp = null;
int status=0;
while(rs.next())
{
otp=rs.getString("otp");
status=rs.getInt("status");
//deposit= rs.getInt("amount");
}
//if(status!=0)
{
if(otpuser.equals(otp))
{
jButton1.setVisible(true);
jButton2.setVisible(false);
jButton3.setVisible(false);
jComboBox1.setVisible(true);
jLabel1.setVisible(true);
jLabel2.setVisible(false);
jLabel3.setVisible(true);
jLabel4.setVisible(true);
jPasswordField1.setVisible(true);
jTextField1.setVisible(true);
jTextField2.setVisible(false);
}
else
{
JOptionPane.showMessageDialog(null, "incvalid otp");
}
}
}
catch(Exception e)
{
}
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
String bank = (String) jComboBox1.getSelectedItem();
String acno = jTextField1.getText();
char[] pass = jPasswordField1.getPassword();
String password = String.valueOf(pass);
try
{
//System.out.println(password);
// System.out.println(acno);
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sambhav", "root", "sam");
//System.out.println("hello");
// Statement stmt=con.createStatement();
String insertquery="update user1 set pass=sha1('"+password+"') where ac_number='"+acno+"'";
//System.out.println("hello1");
PreparedStatement ps1=con.prepareStatement(insertquery);
//System.out.println("hello2");
ps1.executeUpdate();
//System.out.println("updated");
// Class.forName("com.mysql.jdbc.Driver");
//Connection con1 = DriverManager.getConnection("jdbc:mysql://localhost:3306/sambhav", "root", "sam");
Statement stmt=con.createStatement();
//System.out.println(bank);
ResultSet rs=stmt.executeQuery("select mail from "+bank+" where ac_no='"+acno+"'");
//int deposit=0;
String email = null;
int status=0;
while(rs.next())
{
email=rs.getString("mail");
//status=rs.getInt("status");
//deposit= rs.getInt("amount");
}
Properties p = new Properties();
p.put("mail.smtp.host","smtp.gmail.com");
p.put("mail.smtp.port","587");
p.put("mail.smtp.starttls.enable","true");
p.put("mail.smtp.auth","true");
p.put("mail.smtp.ssl.trust","smtp.gmail.com");
p.put("mail.debug","true");
// create object of Authenticator
BabyOfAuthenticator baby = new BabyOfAuthenticator();
// create object of session
Session ses = Session.getInstance(p, baby);
// create object of mime-message to denote
// actual message to be sent to mail server
MimeMessage message = new MimeMessage(ses);
// provide a subject
message.setSubject(" New Password ");
String[] emails = email.split(",");
InternetAddress[] inadrs = new InternetAddress[emails.length];
for(int i = 0; i < emails.length; i++)
{
// create object of internet-address to
// denote email
InternetAddress ina = new InternetAddress(emails[i]);
// store this object inside array
inadrs[i] = ina;
}
// lets specify the types of RCVRS
message.addRecipients(Message.RecipientType.TO, inadrs);
// create some body parts
MimeBodyPart body1 = new MimeBodyPart();//body2 = new MimeBodyPart(),body3 = new MimeBodyPart();
// associate a text with body1
body1.setContent("<p style='color : red;'>New Password of Your Account No : "+acno+"<br>"+password+"</br></p>", "text/html");
//String path ="f:\\a.png";
//File f1 = new File("f:\\a.png");
//File f2 = new File("c:\\Users\\hp\\Downloads\\GUI02.txt");
// associate attachments with body2 and body3
//body2.attachFile(f1);
//body3.attachFile(f2);
// create multipart to store body parts
MimeMultipart parts = new MimeMultipart();
// store all the body parts inside multipart
parts.addBodyPart(body1);
//parts.addBodyPart(body2);
//parts.addBodyPart(body3);
// store multipart inside message
message.setContent(parts);
// send this message to the mail server
Transport.send(message);
System.out.println("Password send");
new login().setVisible(true);
this.dispose();
}
catch(Exception e)
{
}
}//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Reset.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Reset.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Reset.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Reset.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Reset().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JComboBox<String> jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration//GEN-END:variables
}
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
import java.util.Random;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.swing.JOptionPane;
/**
*
* @author hp
*/
public class Reset extends javax.swing.JFrame {
/**
* Creates new form Reset
*/
public Reset() {
initComponents();
jPasswordField1.setVisible(false);
jButton1.setVisible(false);
jButton2.setVisible(false);
jTextField2.setVisible(false);
jLabel2.setVisible(false);
jLabel3.setVisible(false);
}
class BabyOfAuthenticator extends Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
// create object of PA
PasswordAuthentication pa = new PasswordAuthentication("kumarsambhav@srmscet.edu","bhushan15.721");
// return object of PA
return pa;
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jPasswordField1 = new javax.swing.JPasswordField();
jComboBox1 = new javax.swing.JComboBox<>();
jLabel4 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBounds(new java.awt.Rectangle(500, 200, 0, 0));
jLabel1.setText("Account No. : ");
jLabel2.setText("OTP : ");
jLabel3.setText("Password : ");
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "sbi", "pnb", "hdfc", "kotak" }));
jLabel4.setText("Bank : ");
jButton1.setText("Reset");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Check OTP");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("Send OTP");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(50, 50, 50)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addGap(32, 32, 32)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPasswordField1, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
.addComponent(jTextField2))
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(94, 94, 94)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)))
.addContainerGap(56, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(43, 43, 43)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton3))
.addContainerGap(89, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
String bank = (String) jComboBox1.getSelectedItem();
String acno = jTextField1.getText();
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sambhav", "root", "sam");
Statement stmt=con.createStatement();
//System.out.println(bank);
ResultSet rs=stmt.executeQuery("select mail,status from "+bank+" where ac_no='"+acno+"'");
//int deposit=0;
String email = null;
int status=0;
while(rs.next())
{
email=rs.getString("mail");
status=rs.getInt("status");
//deposit= rs.getInt("amount");
}
//if(status!=0)
{
Random random = new Random();
String id = String.format("%04d", random.nextInt(10000));
System.out.println("RAndon is ###########"+id);
Properties p = new Properties();
p.put("mail.smtp.host","smtp.gmail.com");
p.put("mail.smtp.port","587");
p.put("mail.smtp.starttls.enable","true");
p.put("mail.smtp.auth","true");
//p.put("mail.smtp.ssl.trust","smtp.gmail.com");
p.put("mail.debug","true");
// create object of Authenticator
BabyOfAuthenticator baby = new BabyOfAuthenticator();
// create object of session
Session ses = Session.getInstance(p, baby);
// create object of mime-message to denote
// actual message to be sent to mail server
MimeMessage message = new MimeMessage(ses);
// provide a subject
message.setSubject(" OTP ");
String[] emails = email.split(",");
InternetAddress[] inadrs = new InternetAddress[emails.length];
for(int i = 0; i < emails.length; i++)
{
// create object of internet-address to
// denote email
InternetAddress ina = new InternetAddress(emails[i]);
// store this object inside array
inadrs[i] = ina;
}
// lets specify the types of RCVRS
message.addRecipients(Message.RecipientType.TO, inadrs);
// create some body parts
MimeBodyPart body1 = new MimeBodyPart();//body2 = new MimeBodyPart(),body3 = new MimeBodyPart();
// associate a text with body1
body1.setContent("<p style='color : red;'>OTP to change Password <br>"+id+"</br></p>", "text/html");
//String path ="f:\\a.png";
//File f1 = new File("f:\\a.png");
//File f2 = new File("c:\\Users\\hp\\Downloads\\GUI02.txt");
// associate attachments with body2 and body3
//body2.attachFile(f1);
//body3.attachFile(f2);
// create multipart to store body parts
MimeMultipart parts = new MimeMultipart();
// store all the body parts inside multipart
parts.addBodyPart(body1);
//parts.addBodyPart(body2);
//parts.addBodyPart(body3);
// store multipart inside message
message.setContent(parts);
// send this message to the mail server
Transport.send(message);
System.out.println("OTP send");
String insertquery="update "+bank+" set otp="+id+" where ac_no='"+acno+"'";
PreparedStatement ps1=con.prepareStatement(insertquery);
ps1.executeUpdate();
jButton1.setVisible(false);
jButton2.setVisible(true);
jButton3.setVisible(false);
jComboBox1.setVisible(true);
jLabel1.setVisible(true);
jLabel2.setVisible(true);
jLabel3.setVisible(false);
jLabel4.setVisible(true);
jPasswordField1.setVisible(false);
jTextField1.setVisible(true);
jTextField2.setVisible(true);
}
}
catch(Exception e)
{
System.out.println(e);
}
}//GEN-LAST:event_jButton3ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
String bank = (String) jComboBox1.getSelectedItem();
String acno = jTextField1.getText();
String otpuser= jTextField2.getText();
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sambhav", "root", "sam");
Statement stmt=con.createStatement();
//System.out.println(bank);
ResultSet rs=stmt.executeQuery("select otp,status from "+bank+" where ac_no='"+acno+"'");
//int deposit=0;
String otp = null;
int status=0;
while(rs.next())
{
otp=rs.getString("otp");
status=rs.getInt("status");
//deposit= rs.getInt("amount");
}
//if(status!=0)
{
if(otpuser.equals(otp))
{
jButton1.setVisible(true);
jButton2.setVisible(false);
jButton3.setVisible(false);
jComboBox1.setVisible(true);
jLabel1.setVisible(true);
jLabel2.setVisible(false);
jLabel3.setVisible(true);
jLabel4.setVisible(true);
jPasswordField1.setVisible(true);
jTextField1.setVisible(true);
jTextField2.setVisible(false);
}
else
{
JOptionPane.showMessageDialog(null, "incvalid otp");
}
}
}
catch(Exception e)
{
}
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
String bank = (String) jComboBox1.getSelectedItem();
String acno = jTextField1.getText();
char[] pass = jPasswordField1.getPassword();
String password = String.valueOf(pass);
try
{
//System.out.println(password);
// System.out.println(acno);
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sambhav", "root", "sam");
//System.out.println("hello");
// Statement stmt=con.createStatement();
String insertquery="update user1 set pass=sha1('"+password+"') where ac_number='"+acno+"'";
//System.out.println("hello1");
PreparedStatement ps1=con.prepareStatement(insertquery);
//System.out.println("hello2");
ps1.executeUpdate();
//System.out.println("updated");
// Class.forName("com.mysql.jdbc.Driver");
//Connection con1 = DriverManager.getConnection("jdbc:mysql://localhost:3306/sambhav", "root", "sam");
Statement stmt=con.createStatement();
//System.out.println(bank);
ResultSet rs=stmt.executeQuery("select mail from "+bank+" where ac_no='"+acno+"'");
//int deposit=0;
String email = null;
int status=0;
while(rs.next())
{
email=rs.getString("mail");
//status=rs.getInt("status");
//deposit= rs.getInt("amount");
}
Properties p = new Properties();
p.put("mail.smtp.host","smtp.gmail.com");
p.put("mail.smtp.port","587");
p.put("mail.smtp.starttls.enable","true");
p.put("mail.smtp.auth","true");
p.put("mail.smtp.ssl.trust","smtp.gmail.com");
p.put("mail.debug","true");
// create object of Authenticator
BabyOfAuthenticator baby = new BabyOfAuthenticator();
// create object of session
Session ses = Session.getInstance(p, baby);
// create object of mime-message to denote
// actual message to be sent to mail server
MimeMessage message = new MimeMessage(ses);
// provide a subject
message.setSubject(" New Password ");
String[] emails = email.split(",");
InternetAddress[] inadrs = new InternetAddress[emails.length];
for(int i = 0; i < emails.length; i++)
{
// create object of internet-address to
// denote email
InternetAddress ina = new InternetAddress(emails[i]);
// store this object inside array
inadrs[i] = ina;
}
// lets specify the types of RCVRS
message.addRecipients(Message.RecipientType.TO, inadrs);
// create some body parts
MimeBodyPart body1 = new MimeBodyPart();//body2 = new MimeBodyPart(),body3 = new MimeBodyPart();
// associate a text with body1
body1.setContent("<p style='color : red;'>New Password of Your Account No : "+acno+"<br>"+password+"</br></p>", "text/html");
//String path ="f:\\a.png";
//File f1 = new File("f:\\a.png");
//File f2 = new File("c:\\Users\\hp\\Downloads\\GUI02.txt");
// associate attachments with body2 and body3
//body2.attachFile(f1);
//body3.attachFile(f2);
// create multipart to store body parts
MimeMultipart parts = new MimeMultipart();
// store all the body parts inside multipart
parts.addBodyPart(body1);
//parts.addBodyPart(body2);
//parts.addBodyPart(body3);
// store multipart inside message
message.setContent(parts);
// send this message to the mail server
Transport.send(message);
System.out.println("Password send");
new login().setVisible(true);
this.dispose();
}
catch(Exception e)
{
}
}//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Reset.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Reset.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Reset.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Reset.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Reset().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JComboBox<String> jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration//GEN-END:variables
}
No comments:
Post a Comment