Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package business;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.LinkedList;
- /**
- *
- * @author luisdiegoaldana
- */
- public class validarUsuario {
- String username;
- String pass;
- User usuarioForma;
- LinkedList listausuarios = new LinkedList();
- public validarUsuario() {
- username = "";
- pass = "";
- usuarioForma = new User();
- }
- public void leer() throws IOException {
- String archivoTest = "/Users/luisdiegoaldana/NetBeansProjects/Lab6/src/java/business/Passwords.txt";
- BufferedReader in = new BufferedReader(new FileReader(archivoTest));
- String str;
- try {
- while ((str = in .readLine()) != null) {
- // Agregamos a todos los usuarios a una lista encadenada
- listausuarios.add(str);
- }
- // Manejamos la excepcion
- } catch (FileNotFoundException fne) {
- // De momento nada
- System.out.println("no se encontro archivo");
- }
- }
- public boolean valida(User usuarioForma) throws IOException {
- leer();
- // Obtenemos el tamaƱo de la lista
- int numUsuarios = listausuarios.size();
- for (int i = 0; i < numUsuarios; i++) {
- String[] temp = (String) listausuarios.get(i).split("\\|");
- username = temp[0];
- pass = temp[1];
- this.usuarioForma = usuarioForma;
- // Mando a llamar el objeto de User. usuario es el nombre del objeto
- if (this.usuarioForma.getUsuario().equals(this.username)) {
- if (this.usuarioForma.getPassword().equals(this.pass)) return true;
- return false;
- } else {
- return false;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment