Guest User

Untitled

a guest
Jan 22nd, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. <%@ page contentType="text/html" pageEncoding="UTF-8"%>
  2. <%@ page errorPage="error.jsp" %>
  3. <%@ page language="java"%>
  4. <%@ page import="java.sql.*" %>
  5.  
  6. <%!
  7. boolean validateUser(String name, String password) {
  8.  
  9. try {
  10. String connectionURL = "jdbc:mysql://mysql.stud.ntnu.no:3306/kristwin_ov1";
  11. Class.forName("com.mysql.jdbc.Driver").newInstance();
  12. Connection connection = DriverManager.getConnection(connectionURL, "kristwin_progsik", "DhEL1337");
  13.  
  14. // check weather connection is established or not by isClosed() method
  15. if(!connection.isClosed()) {
  16. return true;
  17. }
  18. }
  19. catch(Exception ex) {
  20. //Log this?
  21. } finally {
  22. connection.close();
  23. }
  24. return false;
  25. }
  26. %>
  27.  
  28. <html>
  29. <head>
  30. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  31. <link rel="stylesheet" type="text/css" href="lutstyle.css">
  32. <title>LUT Login Pages</title>
  33. </head>
  34. <body>
  35. <%
  36. if(validateUser(${param.username}, ${param.password})) {
  37. out.println("Success!");
  38. }
  39. else {
  40. out.println("Failed!");
  41. }
  42. %>
  43. </body>
  44. </html>
Add Comment
Please, Sign In to add comment