• Log in or sign up for an account here: https://www.sythe.org/login

Anyone care to help me out?

Joined
Apr 21, 2005
Sythe Gold
0
Messages
773
Hi well I been trying to get this working for about 1 hour now. It is a login system, and you create an account and stuff, but I haven't programmed in a long time so I am getting use to java again and I know this isnt anything good but its for me to get warmed back up. Well here is my code.

Code:
  }
    public void actionPerformed(ActionEvent e) {
    	Object source = e.getSource();
    	if (source == logOn) {
    		try {
    			BufferedReader readUsername = new BufferedReader(new FileReader("username.txt"));
    			String userName = readUsername.readLine();
    			readUsername.close();
    			try {
    				BufferedReader readPassword = new BufferedReader(new FileReader("password.txt"));
    				String passWord = readPassword.readLine();
    				readPassword.close();
    				if (userName.equals(username) && passWord.equals(password)) {
    					JOptionPane.showMessageDialog(this, "Log in Success!", "Success!", JOptionPane.INFORMATION_MESSAGE);
    				} else {
    					JOptionPane.showMessageDialog(this, "Invalid Username/Passowrd!", "Invalid!", JOptionPane.INFORMATION_MESSAGE);
    				}
    			} catch (IOException ioe) {
    			}
    		} catch (IOException ioe) {
    		}
    		return;
    	}

My problem is everytime I try to logon I get invalid username and password no matter what I do. Even though in the username.txt and password.txt it is correct. Anyone care to help me fix this problem?

Thanks.

Fate

EDIT: This is only part of the code.. not the whole thing!
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
try closing the files after you check them? most likly won't work but its worth a shot. :/


and equalsIgnoreCase is another good thing to try and see if that makes it work instead of just equals... :/
 
Ah yeah! I totally forgot about equalsIgnoreCase, I'll go try it out right.

EDIT: I tried it out, apparently it wont even compile with equalsIgnoreCase..

EDIT2: I figured it out, had to add getText to username and password.
 
duelarena.gg
Back
Top