Guest User

Untitled

a guest
Dec 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 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.  
  8. /**
  9. *
  10. * @author luisdiegoaldana
  11. */
  12.  
  13.  
  14. public class validarUsuario{
  15.  
  16. String username;
  17. String pass;
  18. User usuarioForma;
  19.  
  20. public validarUsuario(){
  21. username="";
  22. pass ="";
  23. usuarioForma = new User();
  24.  
  25. }
  26.  
  27. public void leer() throws IOException {
  28.  
  29. String archivoTest = "/Users/luisdiegoaldana/NetBeansProjects/Lab6/src/java/business/Passwords.txt";
  30.  
  31. BufferedReader in = new BufferedReader(new FileReader(archivoTest));
  32. String str;
  33.  
  34.  
  35.  
  36. try {
  37.  
  38. while ((str = in.readLine()) != null) {
  39.  
  40. // Leo linea del archivo de passwords
  41. String[] temp = str.split("\\|");
  42. username = temp[0];
  43. pass = temp[1];
  44.  
  45.  
  46.  
  47.  
  48. }
  49.  
  50.  
  51. // Manejamos la excepcion
  52. } catch (FileNotFoundException fne) {
  53. // De momento nada
  54. System.out.println("no se encontro archivo");
  55. }
  56.  
  57. }
  58.  
  59. public boolean valida(User usuarioForma) throws IOException{
  60. leer();
  61. this.usuarioForma=usuarioForma;
  62. // Mando a llamar el objeto de User. usuario es el nombre del objeto
  63. if(this.usuarioForma.getUsuario().equals(this.username)) {
  64. if(this.usuarioForma.getPassword().equals(this.pass))
  65. return true;
  66. return false;
  67. } else {
  68. return false;
  69. }
  70. }
  71.  
  72.  
  73.  
  74. }
Add Comment
Please, Sign In to add comment