Package controleEstoque.controladores

Source Code of controleEstoque.controladores.ControlLogin

package controleEstoque.controladores;

import controleEstoque.arquivos.Arquivo;
import controleEstoque.arquivos.ControlCarregaArquivos;
import controleEstoque.entidades.Login;
import java.io.IOException;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Christopher
*/
public class ControlLogin {
   
    /**
     * Valida o acesso de um usuário
     * @param login objeto Login contendo usuário e senha
     * @return true se existir.
     * @throws IOException Erro ao abrir arquivo
     */
    public boolean validaAcesso(Login login) throws IOException{
        Login[] vetLogin = carregaArquivo();
        boolean valida = false;
       
        if(vetLogin != null){
            int i = 0;
            while(i < vetLogin.length){
                valida = vetLogin[i].validaAcesso(login.getUsuario(), login.getSenha());              
                if(valida)
                    break;
                i++;
            }
        }
        return valida;
    }
   
    /**
     * Retorna uma lista de objetos do tipo Login com todos os usuários cadastrados
     * @return vetor com todos usuários cadastrados
     * @throws IOException Impossível abrir o arquivo de texto
     */
    private Login[] carregaArquivo() throws IOException{
       
        ControlCarregaArquivos carregaArquivos = new ControlCarregaArquivos(Arquivo.LOGIN);
        String[] linhas = carregaArquivos.retornaStringArquivo();
        Login[] login = null;
       
        if(linhas != null){
            login = new Login[linhas.length/3];
            int i = 0, j = 0, h = 0;
            while(i < linhas.length){
                switch(h){
                    case 0:
                        login[j] = new Login();
                        login[j].setUsuario(linhas[i]);
                        h++;
                    break;
                   
                    case 1:
                        login[j].setSenha(linhas[i].toCharArray());                     
                        h++;
                    break;
                   
                    case 2:
                        login[j].setPermission(linhas[i]);
                        h = 0;
                        j++;
                    break;               
                }              
                i++;               
            }
        }
       
        return login;
       
    }
   
  
}
TOP

Related Classes of controleEstoque.controladores.ControlLogin

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.