Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sub.view;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.scene.control.Alert;
- import javafx.scene.control.Alert.AlertType;
- import javafx.scene.control.Button;
- import javafx.scene.control.CheckBox;
- import javafx.scene.control.ComboBox;
- import javafx.scene.control.TextArea;
- import javafx.scene.control.TextField;
- import javafx.stage.Stage;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.Iterator;
- import org.json.simple.JSONArray;
- import org.json.simple.parser.JSONParser;
- import org.json.simple.parser.ParseException;
- import org.json.simple.JSONObject;
- public class Controller {
- Stage mainStage;
- @FXML
- private Button login;
- @FXML
- private TextField username;
- public void setMainStage(Stage stage) {
- mainStage = stage;
- }
- @FXML
- private void userLogin(ActionEvent evt){
- System.out.println(username.getText());
- System.out.println("Login is " + validateLogin(username.getText()));
- }
- private void createUserList(){
- try{
- String saveDir = "usernameList";
- String saveName = "userlist.dat";
- File temp_Dir = new File(saveDir);
- File temp_Path = new File(saveDir+saveName);
- temp_Dir.mkdir();
- temp_Path.createNewFile();
- ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(saveDir+saveName));
- Hashtable<String,String> userList = new Hashtable<String,String>();
- userList.put("jc2162", "jc2162");
- userList.put("mx63", "mx63");
- userList.put("jf10", "jf10");
- userList.put("rb17", "rb17");
- userList.put("dz112", "dz112");
- output.writeObject(userList);
- }
- catch(FileNotFoundException e){ e.printStackTrace();}
- catch(IOException e){ e.printStackTrace();}
- }
- private boolean validateLogin(String user){
- //createUserList(); // run this to create the userlist file
- try{
- ObjectInputStream input = new ObjectInputStream(new FileInputStream("usernameList"+"userlist.dat"));
- Hashtable<String,String> userList = (Hashtable)input.readObject();
- Enumeration users = userList.keys();
- String key;
- while(users.hasMoreElements()){
- key = (String) users.nextElement();
- if(key.equals(user))
- return true;
- }
- return false;
- }
- catch(FileNotFoundException e){ e.printStackTrace();}
- catch(IOException e){ e.printStackTrace();}
- catch(ClassNotFoundException e){ e.printStackTrace();}
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement