Hi, I'm doing a study planner in java. I'm doing a simple login system. For every user who registers a text file is created holding all of the information inputted during registration. This is the code of a method which the program uses to login the user:
public void loginUser(){
r = new Registration();
r.username = txtUser.getText();
r.password = txtPass.getText();
try{
String line;
SubjectFrame subject = new SubjectFrame();
BufferedReader f = new BufferedReader(new FileReader(r.username + ".txt"));
while((item = f.readLine()) != null){
if(line.equals(r.password)){
dispose();
subject = new SubjectFrame();
subject.setSize(700,600);
subject.setLocation(100,100);
subject.setVisible(true);
}else{
System.out.println("No");
}
}
f.close();
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Wrong information!", "Error", JOptionPane.ERROR_MESSAGE);
}
}
The problem is that when the user inputs wrong details I get 4 'No'('No' is used for debugging instead of an error message). When the user inputs the correct details I get 4 'No' but it proceeds properly. I know it's something concerning the loop but I can't figure it out. I'm still a beginner :(
Anyway thanks in advance!