Advertisement
Guest User

Untitled

a guest
Nov 28th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. public static void login_register() throws IOException, SQLException {
  2. String a, name, password;
  3.  
  4. while (true) {
  5. System.out.print("\nType login or register\n> ");
  6. a = reader.readLine();
  7. if (a.equals("login")) {
  8. System.out.print("\nWhat is your username?\n> ");
  9. name = reader.readLine();
  10. utilizadorUsername = name;
  11. System.out.print("\nWhat is your password?\n> ");
  12. password = reader.readLine();
  13.  
  14. String look = "select username, password from utilizador where username ='" + name + "' and password ='" + password + "';";
  15. ResultSet res = stmt.executeQuery(look);
  16.  
  17. if (!res.next()) {
  18. System.out.println("Wrong information, try again");
  19. continue;
  20. }
  21. else {
  22. System.out.println("\nStatus Logged | Welcome back to DropMusic");
  23. break;
  24. }
  25. }
  26. else if (a.equals("register")) {
  27. System.out.print("\nWhat is your username?\n> ");
  28. name = reader.readLine();
  29. utilizadorUsername = name;
  30. System.out.print("\nWhat is your password? \n> ");
  31. password = reader.readLine();
  32. String look = "select username from utilizador where username ='" + name + "';";
  33. ResultSet res = stmt.executeQuery(look);
  34.  
  35. if (res.next()) {
  36. System.out.println("Username already exists, try again");
  37. continue;
  38. }
  39. else {
  40. String query = "INSERT INTO public.utilizador(\n" +
  41. "\tusername, password)\n" +
  42. "\tVALUES ('" + name + "', '" + password + "');";
  43. stmt.executeUpdate(query);
  44.  
  45. String query2 = "INSERT INTO public.nao_editor(\n" +
  46. "\tutilizador_username)\n" +
  47. "\tVALUES ('"+name+"');";
  48. stmt.executeUpdate(query2);
  49.  
  50. System.out.println("\nStatus Subscribed | Welcome to DropMusic");
  51. break;
  52. }
  53. }
  54. else {
  55. System.out.println("Something went wrong, try again");
  56. continue;
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement