Hey I need some help with my code.. I want it to say 'logged on' when the 'Pass' and 'getPass' is the same. and if its not its says 'logged off'.. but it says that all the time even if its correct. :/. Can Someone Help Me :(
p.s
sorry For My Bad English xd
package ca.sidez.main;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
public class Main extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private static JTextField txtName;
private static JTextField txtPass;
public static String Pass;
public static String Pass2;
public static String getPass;
public static String getName;
public static String File;
public Main() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e1) {
e1.printStackTrace();
}
setResizable(false);
setTitle("Login");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(380, 380);
setLocation(100, 100);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
txtName = new JTextField();
txtName.setBounds(67, 50, 165, 28);
contentPane.add(txtName);
txtName.setColumns(10);
txtPass = new JTextField();
txtPass.setBounds(67, 100, 165, 28);
contentPane.add(txtPass);
txtPass.setColumns(20);
JLabel lblName = new JLabel("Login");
lblName.setBounds(127, 20, 100, 30);
contentPane.add(lblName);
JButton btnLogin = new JButton("Login");
btnLogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
File = txtName.getText();
Share();
}
});
btnLogin.setBounds(60, 311, 117, 29);
contentPane.add(btnLogin);
}
public static void Share() {
try {
//Checks if The Username Exists.
File file = new File(File + ".txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
StringBuffer stringBuffer = new StringBuffer();
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append(line);
stringBuffer.append("\n");
}
fileReader.close();
Pass = stringBuffer.toString();
getPass = txtPass.getText();
getName = txtName.getText();
System.out.println("Clients Password: " + getPass + " For Acc '" + getName + "' ");
System.out.println("The Correct Password For Acc: " + getName + " Is: " + Pass);
if(Pass == getPass) {
System.out.println("Logged In");
} else {
System.out.println("Logged Out");
}
} catch (IOException e) {
System.out.println("Wrong Username Or Password");
}
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Main frame = new Main();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}