From c1ab46fe0180bbcc4dc2be27f4d89e7e0d811afc Mon Sep 17 00:00:00 2001 From: DEEPTI SHARMA <31379739+DEEZZU@users.noreply.github.com> Date: Wed, 2 Oct 2019 10:25:30 +0530 Subject: [PATCH 1/7] Updated the check style of the code --- PROJO/src/java/aqpg/LoginDao.java | 74 +++++++++---------------------- 1 file changed, 21 insertions(+), 53 deletions(-) diff --git a/PROJO/src/java/aqpg/LoginDao.java b/PROJO/src/java/aqpg/LoginDao.java index 9236fa0..4bf18d2 100755 --- a/PROJO/src/java/aqpg/LoginDao.java +++ b/PROJO/src/java/aqpg/LoginDao.java @@ -5,58 +5,26 @@ public class LoginDao { -public static int validate(LoginBean bean) throws SQLException{ -ResultSet rs = null; -boolean records=false; -int status=0; -try{ -Connection con=ConnectionProvider.getCon(); - -PreparedStatement ps=con.prepareStatement("Select * from user_2 where login_name=? and pass=? and type=?"); - -ps.setString(1, bean.getLoginName()); -ps.setString(2, bean.getPass()); -ps.setString(3, bean.getType()); - -rs=ps.executeQuery(); -} -catch(Exception e){} -if(rs!=null && rs.next()!=false) - status=1; -/*finally { - if (rs != null) { - try { - - String loginName; - String pass; - String type; - records=rs.next(); - - do{ - loginName=rs.getString(1); - if(loginName==bean.getLoginName()){ - pass=rs.getString(2); - type=rs.getString(3); - System.out.println(loginName+" "+pass+" "+ type +" "); - if(pass==bean.getPass() && type==bean.getType()) - { - status=1; - - } - break; - } - }while(rs.next()); - } - catch (SQLException ex) { - Logger.getLogger(LoginDao.class.getName()).log(Level.SEVERE, null, ex); +/** +* Returns whether a user exist in our system or not +* @param bean +* @return int : a status code indicating presence of the user +*/ +public static int validate(LoginBean bean) throws SQLException { + ResultSet rs = null; + boolean records=false; + int status=0; + try { + Connection con=ConnectionProvider.getCon(); + PreparedStatement ps=con.prepareStatement("Select * from user_2 where login_name=? and pass=? and type=?"); + ps.setString(1, bean.getLoginName()); + ps.setString(2, bean.getPass()); + ps.setString(3, bean.getType()); + rs=ps.executeQuery(); + } catch(Exception e){} + if (rs != null && rs.next() != false) { + status=1; } - rs.close(); - } - - rs = null; - }*/ - - - return status; + return status; + } } -} \ No newline at end of file From 595dc7447ed1b813afffa0332af12d812291e76d Mon Sep 17 00:00:00 2001 From: DEEPTI SHARMA <31379739+DEEZZU@users.noreply.github.com> Date: Wed, 2 Oct 2019 10:29:56 +0530 Subject: [PATCH 2/7] Added Logging in the code --- PROJO/src/java/aqpg/LoginDao.java | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/PROJO/src/java/aqpg/LoginDao.java b/PROJO/src/java/aqpg/LoginDao.java index 4bf18d2..f3fae15 100755 --- a/PROJO/src/java/aqpg/LoginDao.java +++ b/PROJO/src/java/aqpg/LoginDao.java @@ -11,20 +11,25 @@ public class LoginDao { * @return int : a status code indicating presence of the user */ public static int validate(LoginBean bean) throws SQLException { - ResultSet rs = null; - boolean records=false; - int status=0; + private ResultSet rs = null; + private boolean records=false; + private int status=0; + private static final Logger LOGGER = Logger.getLogger(LoginDao.class.getName()); + try { - Connection con=ConnectionProvider.getCon(); - PreparedStatement ps=con.prepareStatement("Select * from user_2 where login_name=? and pass=? and type=?"); - ps.setString(1, bean.getLoginName()); - ps.setString(2, bean.getPass()); - ps.setString(3, bean.getType()); - rs=ps.executeQuery(); - } catch(Exception e){} - if (rs != null && rs.next() != false) { - status=1; - } + Connection con=ConnectionProvider.getCon(); + PreparedStatement ps=con.prepareStatement("Select * from user_2 where login_name=? and pass=? and type=?"); + ps.setString(1, bean.getLoginName()); + ps.setString(2, bean.getPass()); + ps.setString(3, bean.getType()); + rs=ps.executeQuery(); + } catch(Exception e){ + LOGGER.log(Level.SEVERE, "Exception occured", ex); + } + + if (rs != null && rs.next() != false) { + status=1; + } return status; } } From c5218f0438d219f69f2f7c8d546c8fa46f0d40f3 Mon Sep 17 00:00:00 2001 From: DEEPTI SHARMA <31379739+DEEZZU@users.noreply.github.com> Date: Wed, 2 Oct 2019 10:43:40 +0530 Subject: [PATCH 3/7] Updated the return of the function --- PROJO/src/java/aqpg/LoginDao.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PROJO/src/java/aqpg/LoginDao.java b/PROJO/src/java/aqpg/LoginDao.java index f3fae15..fd683f8 100755 --- a/PROJO/src/java/aqpg/LoginDao.java +++ b/PROJO/src/java/aqpg/LoginDao.java @@ -10,10 +10,10 @@ public class LoginDao { * @param bean * @return int : a status code indicating presence of the user */ -public static int validate(LoginBean bean) throws SQLException { +public static boolean validate(LoginBean bean) throws SQLException { private ResultSet rs = null; - private boolean records=false; - private int status=0; + private boolean records = false; + private boolean isValidUser = false; private static final Logger LOGGER = Logger.getLogger(LoginDao.class.getName()); try { @@ -28,8 +28,8 @@ public static int validate(LoginBean bean) throws SQLException { } if (rs != null && rs.next() != false) { - status=1; + isValidUser = true; } - return status; + return isValidUser; } } From fecbb53ee9a42570ee3fae4d9c468d135130a998 Mon Sep 17 00:00:00 2001 From: DEEPTI SHARMA <31379739+DEEZZU@users.noreply.github.com> Date: Wed, 2 Oct 2019 10:48:23 +0530 Subject: [PATCH 4/7] Updated status code and added error login page --- PROJO/web/loginprocess.jsp | 53 ++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/PROJO/web/loginprocess.jsp b/PROJO/web/loginprocess.jsp index 8dda235..81d9760 100755 --- a/PROJO/web/loginprocess.jsp +++ b/PROJO/web/loginprocess.jsp @@ -22,43 +22,34 @@ <% out.println(obj.getLoginName()+" "+ obj.getPass()+ " "+obj.getType() ); - int status=LoginDao.validate(obj); - out.println(status); - if(status==1){ - out.println("You r successfully logged in"); - session.setAttribute("session","TRUE"); - String name= request.getParameter("loginName"); - session.setAttribute("LoginID", name); + boolean isValidUser = LoginDao.validate(obj); + if (isValidUser) { + out.println("You r successfully logged in"); + session.setAttribute("session","TRUE"); + String name = request.getParameter("loginName"); + session.setAttribute("LoginID", name); + String s=request.getParameter("type"); - String s=request.getParameter("type"); - - if(s.equals("A")) - { - // out.println("here"); + if(s.equals("A")) { %> - + <% - } - else if(s.equals("I")) - { + } + else if(s.equals("I")) { %> - + <% + } + else { + %> + + <% + } } -else -{ -%> - -<% - // out.println("here2"); - } -} - else - { -%> - -<% - out.print("Sorry, login or password error"); + else { + %> + + <% } %> From 4a326c939981a0b4eff0cad81957b737ef7acbf4 Mon Sep 17 00:00:00 2001 From: DEEPTI SHARMA <31379739+DEEZZU@users.noreply.github.com> Date: Wed, 2 Oct 2019 11:02:38 +0530 Subject: [PATCH 5/7] Updated variables --- PROJO/web/loginprocess.jsp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/PROJO/web/loginprocess.jsp b/PROJO/web/loginprocess.jsp index 81d9760..31cf10d 100755 --- a/PROJO/web/loginprocess.jsp +++ b/PROJO/web/loginprocess.jsp @@ -6,36 +6,29 @@ <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@page import="aqpg.LoginDao"%> - - lOGIN PROCESSING PAGE - - - - - + + <% - out.println(obj.getLoginName()+" "+ obj.getPass()+ " "+obj.getType() ); - boolean isValidUser = LoginDao.validate(obj); + boolean isValidUser = LoginDao.validate(userObject); if (isValidUser) { - out.println("You r successfully logged in"); - session.setAttribute("session","TRUE"); - String name = request.getParameter("loginName"); - session.setAttribute("LoginID", name); - String s=request.getParameter("type"); + session.setAttribute("SESSION","true"); + String loginName = request.getParameter("loginName"); + session.setAttribute("USER", loginName); + String userType = request.getParameter("type"); - if(s.equals("A")) { + if(userType.equals("A")) { // user is of Admin Type %> <% } - else if(s.equals("I")) { + else if(userType.equals("I")) { // user is of Instructor Type %> <% From 4e53d1a415c3110999db20f704ba3c983116afe5 Mon Sep 17 00:00:00 2001 From: DEEPTI SHARMA <31379739+DEEZZU@users.noreply.github.com> Date: Wed, 2 Oct 2019 11:12:53 +0530 Subject: [PATCH 6/7] Updated Title --- PROJO/web/loginprocess.jsp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PROJO/web/loginprocess.jsp b/PROJO/web/loginprocess.jsp index 31cf10d..7906b3c 100755 --- a/PROJO/web/loginprocess.jsp +++ b/PROJO/web/loginprocess.jsp @@ -10,7 +10,7 @@ - lOGIN PROCESSING PAGE + LOGIN PROCESSING PAGE From 04f318f41113067e99c1f73dd0e425f8fb0b3009 Mon Sep 17 00:00:00 2001 From: DEEPTI SHARMA <31379739+DEEZZU@users.noreply.github.com> Date: Wed, 2 Oct 2019 11:15:41 +0530 Subject: [PATCH 7/7] created error page --- PROJO/web/errorLogin.jsp | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 PROJO/web/errorLogin.jsp diff --git a/PROJO/web/errorLogin.jsp b/PROJO/web/errorLogin.jsp new file mode 100644 index 0000000..50adf9c --- /dev/null +++ b/PROJO/web/errorLogin.jsp @@ -0,0 +1,11 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + ERROR PAGE + + + No such user exist !! + +