Advertisement
Guest User

Untitled

a guest
Dec 5th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. private void Login(HttpServletRequest request, HttpServletResponse response){
  2. try{
  3. String username = request.getParameter("username");
  4. String password = request.getParameter("password");
  5. Class.forName("com.mysql.jdbc.Driver"); // MySQL database connection
  6. Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/Breakout?" + "user=root&password=");
  7. PreparedStatement pst = conn.prepareStatement("select username,password from Users where username=?");
  8. pst.setString(1, username);
  9. ResultSet rs = pst.executeQuery();
  10. while(rs.next()){
  11. if(BCrypt.checkpw(password,rs.getString("password"))){
  12. System.out.println(username +" ingelogd");
  13. response.sendRedirect("index.jsp");
  14. //request.getRequestDispatcher(request.getContextPath()+"/assets/pages/game.jsp").forward(request,response);
  15. } else {
  16. System.out.println("INLOGGEN MISLUKT");
  17. response.sendRedirect("assets/pages/login.jsp?login=error");
  18. //request.getRequestDispatcher("/assets/pages/login.jsp?login=error").forward(request,response);
  19. }
  20. }
  21. }
  22. catch(Exception e){
  23. System.out.println("Something went wrong !! Please try again");
  24. System.out.println(e);
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement