Skip to content

Commit 69d19f1

Browse files
Add files via upload
1 parent a7b8c0c commit 69d19f1

File tree

4 files changed

+293
-0
lines changed

4 files changed

+293
-0
lines changed

Coding-Testing/usr_Auth/index.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class index{
2+
public static void main(String[] args){
3+
new welcomePage();
4+
}
5+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import java.awt.*;
2+
import javax.swing.*;
3+
import java.awt.event.*;
4+
import java.sql.*;
5+
public class loginForm extends JFrame implements ActionListener{
6+
private Container c;
7+
private JLabel nL, pL;
8+
private JTextField nTF;
9+
private JPasswordField pPF;
10+
private JButton lBtn, cBtn;
11+
private Cursor cur=new Cursor(Cursor.HAND_CURSOR);
12+
private String uNm, uPw, btn;
13+
private JFrame f;
14+
welcomePage wP;
15+
private boolean d=false;
16+
loginForm(){
17+
setTitle("Login Form");
18+
setBounds(100,100,300,150);
19+
c=this.getContentPane();
20+
c.setLayout(null);
21+
c.setBackground(Color.CYAN);
22+
setVisible(true);
23+
setDefaultCloseOperation(EXIT_ON_CLOSE);
24+
25+
nL=new JLabel("User Name");
26+
nL.setBounds(10,30,80,20);
27+
add(nL);
28+
pL=new JLabel("Password");
29+
pL.setBounds(10,60,80,20);
30+
add(pL);
31+
nTF=new JTextField();
32+
nTF.setBounds(110,30,150,20);
33+
add(nTF);
34+
pPF=new JPasswordField();
35+
pPF.setBounds(110,60,150,20);
36+
add(pPF);
37+
lBtn=new JButton("Login");
38+
lBtn.setBounds(30,100,100,20);
39+
lBtn.setCursor(cur);
40+
lBtn.addActionListener(this);
41+
add(lBtn);
42+
cBtn=new JButton("Cancel");
43+
cBtn.setBounds(150,100,100,20);
44+
cBtn.setCursor(cur);
45+
cBtn.addActionListener(this);
46+
add(cBtn);
47+
}
48+
@Override
49+
public void actionPerformed(ActionEvent e){
50+
btn=e.getActionCommand();
51+
if(btn.equals("Login")){
52+
uNm=nTF.getText(); nTF.setText(null);
53+
uPw=pPF.getText(); pPF.setText(null);
54+
validation(uNm,uPw);
55+
}
56+
else if(btn.equals("Cancel") || d==true){
57+
setVisible(false);
58+
wP=new welcomePage();
59+
}
60+
}
61+
void validation(String uNm,String uPw){
62+
String url="jdbc:mysql://localhost:3306/";
63+
String dbNm="RobBot?autoReconnect=true&useSSL=false";
64+
String driver="com.mysql.jdbc.Driver";
65+
String usrNm="root";
66+
String psswd="password";
67+
String[] R = new String[2];
68+
try{
69+
f=new JFrame();
70+
Class.forName(driver);//newInstance();
71+
try{
72+
Connection conn=DriverManager.getConnection(url+dbNm,usrNm,psswd);
73+
Statement stmnt=conn.createStatement();
74+
ResultSet rs=stmnt.executeQuery("SELECT * FROM Users WHERE UNm=\""+uNm+"\"AND UPsswd=\""+uPw+"\"");
75+
while(rs.next()){
76+
try{
77+
String name=rs.getString("Name");
78+
String email=rs.getString("email");
79+
String mob=rs.getString("Mob");
80+
String uname=rs.getString("UNm");
81+
String upsswd=rs.getString("UPsswd");
82+
d=true;
83+
JOptionPane.showMessageDialog(f,"Login Successful");
84+
System.out.format("%s, %s, %s, %s, %s, %s\n",name,email,mob,uname,upsswd);
85+
}catch(SQLException sqle){
86+
JOptionPane.showMessageDialog(f,"Login Failed");
87+
}
88+
}
89+
}catch(SQLException sqle){
90+
JOptionPane.showMessageDialog(f,"Error...Consult Terminal Window");
91+
System.out.println("SQL Exception thrown: "+sqle);
92+
sqle.printStackTrace();
93+
}finally{
94+
if(conn!=null)
95+
conn.close(); conn=null;
96+
}
97+
}catch(ClassNotFoundException cnf){
98+
System.out.println("Driver could not be loaded: "+cnf);
99+
}
100+
}
101+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import java.awt.*;
2+
import javax.swing.*;
3+
import java.awt.event.*;
4+
import java.sql.*;
5+
public class registrationForm extends JFrame implements ActionListener{
6+
private Container c;
7+
private JLabel r,nL,maL,mnL,uL,pL,cpL;
8+
private JTextField nTF,maTF,mnTF,uTF;
9+
private JPasswordField pPF,cpPF;
10+
private Cursor cur;
11+
private String Name,mailID,mobNo,UsrNm,UsrPw,cUsrPw,btn;
12+
private JButton rBtn, cBtn;
13+
private boolean done=false;
14+
registrationForm(){
15+
setTitle("Registration Form");
16+
setBounds(100,10,500,300);
17+
c=this.getContentPane();
18+
c.setLayout(null);
19+
c.setBackground(Color.CYAN);
20+
setVisible(true);
21+
setDefaultCloseOperation(EXIT_ON_CLOSE);
22+
23+
r=new JLabel("Register Now");
24+
r.setFont(new Font("Times New Roman",Font.BOLD,20));
25+
r.setBounds(200,10,200,30);
26+
add(r);
27+
nL=new JLabel("Enter Name");
28+
nL.setBounds(50,100,200,20);
29+
add(nL);
30+
nTF=new JTextField();
31+
nTF.setBounds(250,100,200,20);
32+
add(nTF);
33+
maL=new JLabel("Full email Address");
34+
maL.setBounds(50,120,200,20);
35+
add(maL);
36+
maTF=new JTextField();
37+
maTF.setBounds(250,120,200,20);
38+
add(maTF);
39+
mnL=new JLabel("Mobile number");
40+
mnL.setBounds(50,140,200,20);
41+
add(mnL);
42+
mnTF=new JTextField();
43+
mnTF.setBounds(250,140,200,20);
44+
add(mnTF);
45+
uL=new JLabel("Username");
46+
uL.setBounds(50,160,200,20);
47+
add(uL);
48+
uTF=new JTextField();
49+
uTF.setBounds(250,160,200,20);
50+
add(uTF);
51+
pL=new JLabel("Password");
52+
pL.setBounds(50,180,200,20);
53+
add(pL);
54+
pPF=new JPasswordField();
55+
pPF.setBounds(250,180,200,20);
56+
add(pPF);
57+
cpL=new JLabel("Confirm Password");
58+
cpL.setBounds(50,200,200,20);
59+
add(cpL);
60+
cpPF=new JPasswordField();
61+
cpPF.setBounds(250,200,200,20);
62+
add(cpPF);
63+
64+
cur=new Cursor(Cursor.HAND_CURSOR);
65+
66+
rBtn=new JButton("Register");
67+
rBtn.setCursor(cur);
68+
rBtn.setBounds(60,250,100,20);
69+
rBtn.addActionListener(this);
70+
add(rBtn);
71+
cBtn=new JButton("Cancel");
72+
cBtn.setBounds(310,250,100,20);
73+
cBtn.setCursor(cur);
74+
cBtn.addActionListener(this);
75+
add(cBtn);
76+
}
77+
@Override
78+
public void actionPerformed(ActionEvent e){
79+
btn=e.getActionCommand();
80+
if(btn.equals("Register")){
81+
Name=nTF.getText(); nTF.setText(null);
82+
mailID=maTF.getText(); maTF.setText(null);
83+
mobNo=mnTF.getText(); mnTF.setText(null);
84+
UsrNm=uTF.getText(); uTF.setText(null);
85+
UsrPw=pPF.getText(); pPF.setText(null);
86+
cUsrPw=cpPF.getText(); cpPF.setText(null);
87+
if(UsrPw.equals(cUsrPw)==true)
88+
sendD2db(Name,mailID,mobNo,UsrNm,UsrPw);
89+
}
90+
else if(btn.equals("Cancel"))
91+
setVisible(false);
92+
if(done==true){
93+
setVisible(false);
94+
new welcomePage();
95+
}
96+
}
97+
private void sendD2db(String n,String ma,String mn,String un,String up){
98+
String url="jdbc:mysql://localhost:3306/";
99+
String dbNm="RobBot?autoReconnect=true&useSSL=false";
100+
String driver="com.mysql.jdbc.Driver";
101+
String usrNm="root";
102+
String psswd="password";
103+
JFrame f;
104+
try{
105+
Class.forName(driver);//newInstance();
106+
f=new JFrame();
107+
try{
108+
Connection conn=DriverManager.getConnection(url+dbNm,usrNm,psswd);
109+
Statement stmnt=conn.createStatement();
110+
stmnt.executeUpdate("INSERT INTO Users VALUES(\""+n+"\",\""+ma+"\",\""+mn+"\",\""+un+"\",\""+up+"\")");
111+
JOptionPane.showMessageDialog(f,"Registration Successful");
112+
done=true;
113+
if(conn!=null){
114+
conn.close();
115+
conn=null;
116+
}
117+
}catch(SQLException sqle){
118+
JOptionPane.showMessageDialog(f,"Error...Consult Terminal Window");
119+
System.out.println("SQL Exception thrown: "+sqle);
120+
sqle.printStackTrace();
121+
}
122+
}catch(ClassNotFoundException cnf){
123+
System.out.println("Driver could not be loaded: "+cnf);
124+
}
125+
}
126+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import java.awt.*;
2+
import javax.swing.*;
3+
import java.awt.event.*;
4+
import javax.imageio.ImageIO;
5+
public class welcomePage extends JFrame implements ActionListener{
6+
private JLabel welcome, choice;
7+
private JButton lBtn, rBtn, xBtn;
8+
private Cursor cur=new Cursor(Cursor.HAND_CURSOR);
9+
private String btn;
10+
registrationForm rF;
11+
loginForm lF;
12+
private Container c;
13+
welcomePage(){
14+
setTitle("Welcome Page");
15+
setBounds(150,100,500,500);
16+
c=this.getContentPane();
17+
c.setLayout(null);
18+
c.setBackground(Color.GREEN);
19+
setVisible(true);
20+
setDefaultCloseOperation(EXIT_ON_CLOSE);
21+
22+
welcome=new JLabel("Welcome to RobBot");
23+
welcome.setBounds(150,50,300,100);
24+
welcome.setFont(new Font("SansSerif",Font.BOLD,20));
25+
add(welcome);
26+
choice=new JLabel("Please choose correct option");
27+
choice.setBounds(150,150,300,50);
28+
add(choice);
29+
lBtn=new JButton("Login");
30+
lBtn.setBounds(150,200,100,30);
31+
lBtn.setCursor(cur);
32+
lBtn.addActionListener(this);
33+
add(lBtn);
34+
rBtn=new JButton("Register");
35+
rBtn.setBounds(250,200,100,30);
36+
rBtn.setCursor(cur);
37+
rBtn.addActionListener(this);
38+
add(rBtn);
39+
xBtn=new JButton("Close");
40+
xBtn.setBounds(200,250,100,50);
41+
xBtn.setCursor(cur);
42+
xBtn.addActionListener(this);
43+
add(xBtn);
44+
}
45+
@Override
46+
public void actionPerformed(ActionEvent e){
47+
btn=e.getActionCommand();
48+
if(btn.equals("Login")){
49+
setVisible(false);
50+
lF=new loginForm();
51+
}
52+
else if(btn.equals("Register")){
53+
setVisible(false);
54+
rF=new registrationForm();
55+
}
56+
else if(btn.equals("Close")){
57+
setVisible(false);
58+
System.exit(0);
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)