Validation of Java Login

Asked

Viewed 96 times

2

I’m in need of a help with a college job, where I need to do a login validation. The application is in Java, Javafx interface, using the Mysql database. My difficulty is understanding how to search and compare what the user enters with the database information. Follow the current code below:

LOGIN CONTROLLER

package application.controllers;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;

public class LoginController {
    
    private AnchorPane rootLayout;
    
    @FXML
    private TextField txtNomeUsuario;
    @FXML
    private TextField txtSenha;
    @FXML
    private Button btnEntrar;
    
    
    @FXML
    private void logar(ActionEvent event) {
        
        String nomeUsuarioLogin = txtNomeUsuario.getText();
        String senhaUsuarioLogin = txtSenha.getText();
        
        //Aqui eu não sei o que fazer

    }
    
    
}

BASE CONNECTION

package application.models.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionBase {
    
    protected Connection conexao;
    
    public Connection open() {
        
        try {
            
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("Driver Ok");
            
            conexao = DriverManager.getConnection("jdbc:mysql://localhost:3306/pi_grupo6", "root", "ROOT");
            
            System.out.println("conexão ok");
            return conexao;
        } catch (SQLException | ClassNotFoundException e) {

            e.printStackTrace();
        }
        return null;
    }
    
    public void close() {
        try {
                if(conexao != null)
                    conexao.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
    }


}

JAVAFX SCREEN

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="415.0" prefWidth="476.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.controllers.LoginController">
   <children>
      <BorderPane prefHeight="200.0" prefWidth="200.0" />
      <Label alignment="CENTER" layoutX="140.0" layoutY="220.0" prefHeight="32.0" prefWidth="196.0" text="Senha">
         <font>
            <Font size="22.0" />
         </font>
      </Label>
      <TextField fx:id="txtNomeUsuario" layoutX="46.0" layoutY="164.0" prefHeight="25.0" prefWidth="385.0">
         <font>
            <Font size="14.0" />
         </font>
      </TextField>
      <Button fx:id="btnEntrar" layoutX="188.0" layoutY="336.0" mnemonicParsing="false" prefHeight="39.0" prefWidth="102.0" text="Entrar">
         <font>
            <Font size="18.0" />
         </font>
      </Button>
      <PasswordField fx:id="txtSenha" layoutX="47.0" layoutY="252.0" prefHeight="25.0" prefWidth="382.0">
         <font>
            <Font size="14.0" />
         </font>
      </PasswordField>
      <Label alignment="CENTER" layoutX="140.0" layoutY="132.0" prefHeight="32.0" prefWidth="196.0" text="Nome de Usuário">
         <font>
            <Font size="22.0" />
         </font>
      </Label>
      <Label alignment="CENTER" contentDisplay="CENTER" layoutX="8.0" layoutY="7.0" prefHeight="86.0" prefWidth="460.0" text="Sistema de Controle de Contas" textAlignment="CENTER">
         <font>
            <Font name="System Bold" size="30.0" />
         </font>
      </Label>
   </children>
</AnchorPane>

Anyone who can help, thank you so much :)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.