Advertisement
Guest User

Untitled

a guest
Nov 27th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. package database;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.util.ArrayList;
  7.  
  8. import database.mainConnection;
  9.  
  10. public class userUtils extends mainConnection {
  11.  
  12. public static void main(String[] args ) throws Exception {
  13. userLogin("mattia",hash("password");
  14.  
  15. }
  16.  
  17.  
  18. /*public static Boolean registerUser(String name, String surname, String username, String email, String password, String Affiliation, String dateOfBirth) throws Exception {
  19. Connection con = getConnection();
  20. // 0000-00-00 format date
  21.  
  22. PreparedStatement query = con.prepareStatement("INSERT INTO users (UserID, Username, Email, Password, Name, Surname, BirthDate, Affiliation) VALUES (?,?,?,?,?,?,?,?)");
  23.  
  24. query.executeUpdate();
  25. return false;
  26. }*/
  27.  
  28. public static Boolean userLogin(String username, String password) throws Exception {
  29. Boolean bool = null;
  30. try{
  31. Connection con = getConnection();
  32. PreparedStatement query = con.prepareStatement("SELECT * FROM users WHERE Username=? AND Password=?");
  33. query.setString(1, username);
  34. query.setString(2, password);
  35.  
  36. ResultSet result = query.executeQuery();
  37.  
  38. if(result.next()) {
  39. bool = true;
  40. }
  41.  
  42. } catch(Exception e) {
  43. e.printStackTrace();
  44. }
  45. return bool;
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement