Advertisement
Guest User

Untitled

a guest
Aug 27th, 2020
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.97 KB | None | 0 0
  1. package sas.kacper.itemsapp;
  2.  
  3. import java.security.MessageDigest;
  4. import java.security.NoSuchAlgorithmException;
  5.  
  6. import javax.xml.bind.DatatypeConverter;
  7.  
  8. import javafx.application.Application;
  9.  
  10. import javafx.scene.Scene;
  11. import javafx.scene.control.Button;
  12. import javafx.scene.control.TextField;
  13. import javafx.scene.control.PasswordField;
  14. import javafx.scene.control.Alert;
  15. import javafx.scene.control.Alert.AlertType;
  16. import javafx.scene.control.ButtonType;
  17. import javafx.scene.layout.VBox;
  18. import javafx.scene.layout.HBox;
  19. import javafx.scene.Node;
  20. import javafx.scene.text.Text;
  21. import javafx.scene.image.Image;
  22. import javafx.scene.image.ImageView;
  23.  
  24. import javafx.stage.Stage;
  25.  
  26. import javafx.event.ActionEvent;
  27. import javafx.event.EventHandler;
  28.  
  29. import javafx.geometry.Pos;
  30.  
  31. import sas.kacper.itemsapp.LoginAuthenticator;
  32.  
  33. public class MainWindow extends Application {
  34.    
  35.     @Override
  36.     public void start(Stage primaryStage) {
  37.        
  38.         VBox mainPane = new VBox(10);
  39.        
  40.         Image iLogo = new Image("file:java.png", true);
  41.         ImageView ivLogo = new ImageView();
  42.         ivLogo.setImage(iLogo);
  43.        
  44.         Text lText = new Text("Nazwa użytkownika");
  45.         Text pText = new Text("Hasło");
  46.         TextField lField = new TextField();
  47.         PasswordField pField = new PasswordField();
  48.         Button bLogin = new Button("Log In!");
  49.        
  50.         bLogin.setOnAction(new EventHandler<ActionEvent>() {
  51.             @Override
  52.             public void handle(ActionEvent e) {
  53.                 String userLogin="", userHash="";
  54.                 userLogin = lField.getText();
  55.                
  56.                 try {
  57.                     MessageDigest crypt = MessageDigest.getInstance("MD5");
  58.                     crypt.update((pField.getText()).getBytes());
  59.                     userHash = (DatatypeConverter.printHexBinary(crypt.digest())).toLowerCase();
  60.                 } catch(NoSuchAlgorithmException exc) {
  61.                     exc.printStackTrace();
  62.                 }
  63.                
  64.                 Alert aAlert = new Alert(AlertType.INFORMATION);
  65.                 ((Stage)aAlert.getDialogPane().getScene().getWindow()).getIcons().add(new Image("file:java.png"));
  66.                 aAlert.setContentText("Wszystko ok!");
  67.                 aAlert.setTitle("Zalogowany!");
  68.                
  69.                 if(!(LoginAuthenticator.checkLogin(userLogin, userHash))) {
  70.                     aAlert.setAlertType(AlertType.ERROR);
  71.                     aAlert.setContentText("Coś poszło nie tak!");
  72.                     aAlert.setTitle("Błąd");
  73.                 }
  74.                
  75.                 aAlert.setHeaderText(null);
  76.                 aAlert.showAndWait();
  77.                
  78.             }
  79.         });
  80.        
  81.         lField.setMaxWidth(250);
  82.         pField.setMaxWidth(250);
  83.         lField.setAlignment(Pos.CENTER);
  84.         pField.setAlignment(Pos.CENTER);
  85.        
  86.         mainPane.setAlignment(Pos.CENTER);
  87.         mainPane.setStyle("-fx-background-color: #FFFFFF;");
  88.         mainPane.getChildren().addAll(ivLogo, new Text(), new Text(), lText, lField, pText, pField, new Text(), bLogin);
  89.        
  90.         Scene mainScene = new Scene(mainPane, 450, 600);
  91.        
  92.         primaryStage.setTitle("Log In!");
  93.         primaryStage.setResizable(false);
  94.         primaryStage.setScene(mainScene);
  95.         primaryStage.getIcons().add(new Image("file:java.png"));
  96.         primaryStage.show();
  97.        
  98.     }
  99.    
  100.     public static void main(String ... args) {
  101.         launch(args);
  102.     }
  103.  
  104. }
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement