Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void login_register() throws IOException, SQLException {
- String a, name, password;
- while (true) {
- System.out.print("\nType login or register\n> ");
- a = reader.readLine();
- if (a.equals("login")) {
- System.out.print("\nWhat is your username?\n> ");
- name = reader.readLine();
- utilizadorUsername = name;
- System.out.print("\nWhat is your password?\n> ");
- password = reader.readLine();
- String look = "select username, password from utilizador where username ='" + name + "' and password ='" + password + "';";
- ResultSet res = stmt.executeQuery(look);
- if (!res.next()) {
- System.out.println("Wrong information, try again");
- continue;
- }
- else {
- System.out.println("\nStatus Logged | Welcome back to DropMusic");
- break;
- }
- }
- else if (a.equals("register")) {
- System.out.print("\nWhat is your username?\n> ");
- name = reader.readLine();
- utilizadorUsername = name;
- System.out.print("\nWhat is your password? \n> ");
- password = reader.readLine();
- String look = "select username from utilizador where username ='" + name + "';";
- ResultSet res = stmt.executeQuery(look);
- if (res.next()) {
- System.out.println("Username already exists, try again");
- continue;
- }
- else {
- String query = "INSERT INTO public.utilizador(\n" +
- "\tusername, password)\n" +
- "\tVALUES ('" + name + "', '" + password + "');";
- stmt.executeUpdate(query);
- String query2 = "INSERT INTO public.nao_editor(\n" +
- "\tutilizador_username)\n" +
- "\tVALUES ('"+name+"');";
- stmt.executeUpdate(query2);
- System.out.println("\nStatus Subscribed | Welcome to DropMusic");
- break;
- }
- }
- else {
- System.out.println("Something went wrong, try again");
- continue;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement