public boolean login(final String userName,final String hashedPassword){
  final Connection con=Database.getConnection();
  try {
    PreparedStatement ps=con.prepareStatement("select username from  ta_users where username = ? and password = ?");
    ps.setString(1,userName);
    ps.setString(2,hashedPassword);
    final ResultSet rs=ps.executeQuery();
    if (!rs.next()) {
      return false;
    }
    ps.close();
    rs.close();
    ps=con.prepareStatement("update ta_users set lastLogin = ? where username = ? ");
    ps.setTimestamp(1,new Timestamp(System.currentTimeMillis()));
    ps.setString(2,userName);
    ps.execute();
    ps.close();
    return true;
  }
 catch (  final SQLException sqle) {
    s_logger.log(Level.SEVERE,"Error validating password name:" + userName + " : "+ " pwd:"+ hashedPassword,sqle);
    throw new IllegalStateException(sqle.getMessage());
  }
 finally {
    DbUtil.closeConnection(con);
  }
}

public boolean login ( final String userName , final String hashedPassword ) { final Connection con = Database . getConnection ( ) ; try { PreparedStatement ps = con . prepareStatement ( "select username from  ta_users where username = ? and password = ?" ) ; ps . setString ( 1 , userName ) ; ps . setString ( 2 , hashedPassword ) ; final ResultSet rs = ps . executeQuery ( ) ; if ( ! rs . next ( ) ) { return false ; } ps . close ( ) ; rs . close ( ) ; ps = con . prepareStatement ( "update ta_users set lastLogin = ? where username = ? " ) ; ps . setTimestamp ( 1 , new Timestamp ( System . currentTimeMillis ( ) ) ) ; ps . setString ( 2 , userName ) ; ps . execute ( ) ; ps . close ( ) ; return true ; } catch ( final SQLException sqle ) { s_logger . log ( Level . SEVERE , "Error validating password name:" + userName + " : " + " pwd:" + hashedPassword , sqle ) ; throw new IllegalStateException ( sqle . getMessage ( ) ) ; } finally { DbUtil . closeConnection ( con ) ; } }
validate the username password , returning true if the user is able to login . this has the side effect of updating the users last login time .
