Guest User

Untitled

a guest
Dec 23rd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. package business;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileReader;
  5. import java.io.FileNotFoundException;
  6. import java.io.IOException;
  7. import java.util.LinkedList;
  8.  
  9. /**
  10.  *
  11.  * @author luisdiegoaldana
  12.  */
  13.  
  14.  
  15. public class validarUsuario {
  16.  
  17.     String username;
  18.     String pass;
  19.     User usuarioForma;
  20.     LinkedList listausuarios = new LinkedList();
  21.  
  22.     public validarUsuario() {
  23.         username = "";
  24.         pass = "";
  25.         usuarioForma = new User();
  26.     }
  27.  
  28.     public void leer() throws IOException {
  29.  
  30.         String archivoTest = "/Users/luisdiegoaldana/NetBeansProjects/Lab6/src/java/business/Passwords.txt";
  31.  
  32.         BufferedReader in = new BufferedReader(new FileReader(archivoTest));
  33.         String str;
  34.  
  35.         try {
  36.  
  37.             while ((str = in .readLine()) != null) {
  38.                 // Agregamos a todos los usuarios a una lista encadenada
  39.                 listausuarios.add(str);
  40.             }
  41.  
  42.             // Manejamos la excepcion
  43.         } catch (FileNotFoundException fne) {
  44.             // De momento nada
  45.             System.out.println("no se encontro archivo");
  46.         }
  47.  
  48.  
  49.     }
  50.  
  51.     public boolean valida(User usuarioForma) throws IOException {
  52.  
  53.         leer();
  54.  
  55.         // Obtenemos el tamaƱo de la lista
  56.         int numUsuarios = listausuarios.size();
  57.  
  58.         for (int i = 0; i < numUsuarios; i++) {
  59.  
  60.             String[] temp = (String) listausuarios.get(i).split("\\|");
  61.  
  62.             username = temp[0];
  63.             pass = temp[1];
  64.  
  65.             this.usuarioForma = usuarioForma;
  66.  
  67.             // Mando a llamar el objeto de User. usuario es el nombre del objeto
  68.             if (this.usuarioForma.getUsuario().equals(this.username)) {
  69.                 if (this.usuarioForma.getPassword().equals(this.pass)) return true;
  70.                 return false;
  71.             } else {
  72.                 return false;
  73.             }
  74.  
  75.         }
  76.     }
  77.  
  78.  
  79.  
  80. }
Add Comment
Please, Sign In to add comment