diff --git a/PROJO/src/java/aqpg/LoginDao.java b/PROJO/src/java/aqpg/LoginDao.java index 9236fa0..fd683f8 100755 --- a/PROJO/src/java/aqpg/LoginDao.java +++ b/PROJO/src/java/aqpg/LoginDao.java @@ -5,58 +5,31 @@ 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); - } - rs.close(); - } - - rs = null; - }*/ - - - return status; +/** +* Returns whether a user exist in our system or not +* @param bean +* @return int : a status code indicating presence of the user +*/ +public static boolean validate(LoginBean bean) throws SQLException { + private ResultSet rs = null; + private boolean records = false; + private boolean isValidUser = false; + 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){ + LOGGER.log(Level.SEVERE, "Exception occured", ex); + } + + if (rs != null && rs.next() != false) { + isValidUser = true; + } + return isValidUser; + } } -} \ No newline at end of file diff --git a/PROJO/web/loginprocess.jsp b/PROJO/web/loginprocess.jsp index 8dda235..31cf10d 100755 --- a/PROJO/web/loginprocess.jsp +++ b/PROJO/web/loginprocess.jsp @@ -6,59 +6,43 @@ <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@page import="aqpg.LoginDao"%> - - lOGIN PROCESSING PAGE - - - - - + + <% - 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(userObject); + if (isValidUser) { + session.setAttribute("SESSION","true"); + String loginName = request.getParameter("loginName"); + session.setAttribute("USER", loginName); + String userType = request.getParameter("type"); - String s=request.getParameter("type"); - - if(s.equals("A")) - { - // out.println("here"); + if(userType.equals("A")) { // user is of Admin Type %> - + <% - } - else if(s.equals("I")) - { + } + else if(userType.equals("I")) { // user is of Instructor Type %> - + <% + } + else { + %> + + <% + } } -else -{ -%> - -<% - // out.println("here2"); - } -} - else - { -%> - -<% - out.print("Sorry, login or password error"); + else { + %> + + <% } %>