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;
- /**
- *
- * @author luisdiegoaldana
- */
- public class validarUsuario{
- String username;
- String pass;
- User usuarioForma;
- 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) {
- // Leo linea del archivo de passwords
- String[] temp = str.split("\\|");
- username = temp[0];
- pass = temp[1];
- }
- // Manejamos la excepcion
- } catch (FileNotFoundException fne) {
- // De momento nada
- System.out.println("no se encontro archivo");
- }
- }
- public boolean valida(User usuarioForma) throws IOException{
- leer();
- 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