#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    13
    Rep Power
    0

    How to log in Users from a text file?


    Suppose there was a text file that looked like this:

    UserName1
    Password1
    UserName2
    Password2
    And there was a GUI that logged you in assuming both the user and its adjacent password match.

    ----

    I have looked for tutorials that deal with this and even tried going for a database although for standard Eclipse that is not possible. I need Netbeans for that....


    Code:
    public void actionPerformed(ActionEvent e) {
    
    String record = null;
    FileReader in = null;
    try {
    	in = new FileReader("login.txt");
    	BufferedReader bin = new BufferedReader(in);
    	record = new String();
        while ((record = bin.readLine()) != null) {
    	 
        	if (fielduser.getText().contentEquals(record))
    		foundUser = true;
    	    if (fieldPass.getText().contentEquals(record))
    		foundPassword = true;
    		}
            bin.close();
    		bin = null;
    		
    } catch (IOException ioe) {
     fielduser.setText("IOProblem");
    						}
    
     if (foundUser == true && foundPassword == true) {
    	System.out.println ("Logged in");
    
    	}
    
    	}
    	});
    This is what I have so far but it keeps throwing me a "IOProblem"
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    it keeps throwing me a "IOProblem"
    Add a call to the printStackTrace() method in the catch block to get the reason for the error:
    ioe.printStackTrace();
    that should help you solve the problem if you know what it is.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    13
    Rep Power
    0
    Thanks- I managed to fix that bug. However the main problem is I don't know how to link the user and his/her affiliated pass together.

    If someone puts his user and any existing pass he can log in.
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    how to link the user and his/her affiliated pass together.
    Does the file link the userid and his password?
    Userid on one line, password on the very next line.
    Change the logic to read the next line (the password) when a match on userid is found.

IMN logo majestic logo threadwatch logo seochat tools logo