Javafx - Login System - Can’t Verify If Username Is in Arraylist

Asked

Viewed 13 times

-1

I am developing a Customer Service program (just to practice) and I have reached a point where I need to check if the user name exists in the "database" which, in this case, is in the ArrayList.
I record the customer information and when I try to enter it in the login it gives as false. Some parts of the code are like this:

LOGIN METHOD:

public void carregarLogin(){
        String mensagemBot = txtBotRecente.getText();
        String mensagemUsuario = txtMensagem.getText();
        
        txtUsuarioRecente.setText(mensagemUsuario);
        txtBotAntiga.setText(mensagemBot);
        txtMensagem.clear();
        
        boolean nomeOK = listaDeClientes.contains(mensagemUsuario);
        
        if(nomeOK == true){
            System.out.println("TESTE: VERDADEIRO");
        }else{
            System.out.println("TESTE: FALSO");
        }
        
        if("cancelar".equalsIgnoreCase(mensagemUsuario)){
            txtMensagem.clear();
            alertaCancelado();
            carregarMensagemInicial();
        }
    }

CUSTOMER REGISTRATION METHOD:

public void cadastrarCliente(){
        Clientes novoCliente = new Clientes(nome, email, senha);
        listaDeClientes.add(novoCliente);
    }

CUSTOMER CLASS:

public class Clientes {
    private String nome;
    private String email;
    private String senha;

    public Clientes(String nome, String email, String senha) {
        this.nome = nome;
        this.email = email;
        this.senha = senha;
    }
    
    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getSenha() {
        return senha;
    }

    public void setSenha(String senha) {
        this.senha = senha;
    }

    @Override
    public String toString() {
        return nome + " : " + email + " : " + senha;
    }
    
}

I hope someone can tell me what to do to check if the username is valid.

Obs: the code is obviously not complete. Anything anyone needs I can send here.

  • Please edit the question to limit it to a specific problem with sufficient detail to identify an appropriate answer.

  • Welcome to Stack Overflow! Please explain the problem better, and if possible restrict code to a [mcve], as the problem is not noticeable to your question. See Help Center How to Ask. And also do our [tour].

No answers

Browser other questions tagged

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