daily pastebin goal
73%
SHARE
TWEET

Untitled

a guest Jun 29th, 2018 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package LogMeOn;
  7.  
  8. import javafx.application.Application;
  9. import javafx.geometry.Insets;
  10. import javafx.geometry.Pos;
  11. import javafx.scene.Scene;
  12. import javafx.scene.control.Button;
  13. import javafx.scene.control.Label;
  14. import javafx.scene.control.PasswordField;
  15. import javafx.scene.control.TextField;
  16. import javafx.scene.layout.GridPane;
  17. import javafx.scene.paint.Color;
  18. import javafx.scene.text.Text;
  19. import javafx.stage.Stage;
  20. import java.io.BufferedWriter;
  21. import java.io.File;
  22. import java.io.FileWriter;
  23. import java.io.IOException;
  24. import java.util.Date;
  25.  
  26. public class Main extends Application {
  27.  
  28.     Stage window;
  29.  
  30.     @Override
  31.     public void start(Stage primaryStage) {
  32.         window = primaryStage;
  33.         window.setTitle( "LogON!" );
  34.  
  35.         GridPane gridPane = new GridPane();
  36.         gridPane.setAlignment( Pos.CENTER );
  37.         gridPane.setPadding( new Insets( 10, 10, 10, 10 ) );
  38.         gridPane.setVgap( 8 );
  39.         gridPane.setHgap( 10 );
  40.  
  41.         //login welcome
  42.         Text welcome = new Text( "Please Sign in Below." );
  43.         gridPane.setConstraints( welcome, 0, 0, 2, 1 );
  44.  
  45.         //Username label
  46.         Label userName = new Label( "Username: " );
  47.         gridPane.setConstraints( userName, 0, 1 );
  48.  
  49.         //username textfield
  50.  
  51.         TextField userNameInput = new TextField();
  52.         gridPane.setConstraints( userNameInput, 1, 1 );
  53.  
  54.         //password label
  55.         Label pass = new Label( "Password: " );
  56.         gridPane.setConstraints( pass, 1, 2 );
  57.  
  58.         //pass input
  59.         PasswordField passinput = new PasswordField();
  60.         gridPane.setConstraints( passinput, 1, 2 );
  61.  
  62.         //login BUTTON
  63.         Button loginButton = new Button( "Login" );
  64.         gridPane.setConstraints( loginButton, 1, 4 );
  65.  
  66.         //reset BUTTON
  67.         Button resetButton = new Button( "Clear Text" );
  68.         gridPane.setConstraints( resetButton, 1, 5 );
  69.  
  70.  
  71.  
  72.  
  73.         //NIST AC-8 WARNING
  74.         Text warning = new Text( "Warning:\n" +
  75.                 "This system is intended for authorized users. \n" +
  76.                 "By using this system you agree to the monitoring and\n" +
  77.                 "recording of information entered. \n" +
  78.                 "Unauthorized access attempts are strictly monitored\n" +
  79.                 "Behavior identified in the Acceptable Use Policy is enforced" );
  80.         gridPane.setConstraints( warning, 0, 6, 3, 2 );
  81.  
  82.         final Text alert = new Text();
  83.         gridPane.setConstraints( alert, 1, 10 );
  84.  
  85.         gridPane.getChildren().addAll( welcome, userName, userNameInput, pass, passinput, loginButton,resetButton, warning );
  86.  
  87.         //button click action
  88.         loginButton.setOnAction( event -> {
  89.  
  90.             //authenticate user
  91.  
  92.             boolean isValid = authenticate( userNameInput.getText(), passinput.getText() );
  93.  
  94.             //NIST AC-7 logon attempts
  95.  
  96.             int loginCounter = counter();
  97.             int maxLogin = 3;
  98.  
  99.             //if statements
  100.             if (loginCounter == maxLogin) {
  101.                 gridPane.setVisible( false );
  102.                 GridPane gridPane2 = new GridPane();
  103.                 gridPane2.setAlignment( Pos.CENTER );
  104.                 gridPane2.setPadding( new Insets( 10, 10, 10, 10 ) );
  105.                 gridPane2.setVgap( 8 );
  106.                 gridPane2.setHgap( 10 );
  107.                 Text errorLogin = new Text( "Failed Attempt Logged\n"
  108.                         + "Incorrect Username and Password has been entered 3 times\n"
  109.                         + "Contact Administrator for password reset" );
  110.  
  111.                 errorLogin.setFill( Color.RED );
  112.                 gridPane2.setConstraints( errorLogin, 0, 0, 2, 2 );
  113.  
  114.                 gridPane2.getChildren().addAll( errorLogin );
  115.                 Scene scene = new Scene( gridPane2, 500, 350 );
  116.                 window.setScene( scene );
  117.                 window.show();
  118.  
  119.             } else if (isValid != true && loginCounter < maxLogin) {
  120.  
  121.                 final Text tryAgain = new Text();
  122.                 gridPane.setConstraints( tryAgain, 1, 8 );
  123.                 tryAgain.setFill( Color.RED );
  124.                 tryAgain.setText( "Login Unsuccessful, Please Try Again." );
  125.                 maxLogin++;
  126.             } else {
  127.  
  128.                 gridPane.setVisible( false );
  129.                 GridPane gridPane5 = new GridPane();
  130.                 gridPane5.setAlignment( Pos.CENTER );
  131.                 // Set gap between the components
  132.                 // Larger numbers mean bigger spaces
  133.                 gridPane5.setHgap( 10 );
  134.                 gridPane5.setVgap( 10 );
  135.                 Text hello = new Text( "Welcome " + userNameInput.getText() + "!\n" );
  136.                 hello.setFill( Color.BLACK );
  137.                 gridPane5.setConstraints( hello, 0, 0, 2, 1 );
  138.                 gridPane5.getChildren().addAll( hello );
  139.  
  140.                 Scene scene3 = new Scene( gridPane5, 500, 400 );
  141.                 window.setScene( scene3 );
  142.                 window.show();
  143.  
  144.  
  145.             }
  146.         } );
  147.  
  148.         resetButton.setOnAction( event ->{
  149.             userNameInput.setText( null );
  150.             passinput.setText( null );
  151.                 }
  152.  
  153.  
  154.         );
  155.  
  156.  
  157.  
  158.         Scene scene = new Scene( gridPane, 500, 350 );
  159.         window.setScene( scene );
  160.         window.show();
  161.  
  162.  
  163.     }
  164.     //LOGGER
  165.     File filename;
  166.     {
  167.         filename = new File( "src/log.txt" );
  168.     }
  169.  
  170.     final boolean append = true;
  171.     BufferedWriter writer = null;
  172.  
  173.     //tracker variables
  174.     Date date = new Date();
  175.     private int track = 0;
  176.     public int attempts;
  177.  
  178.  
  179.     private int counter() {
  180.         int plus = track++;
  181.         attempts = plus + 1;
  182.         return plus;
  183.     }
  184.  
  185.     public static void main(String[] args) {
  186.         launch(args);
  187.     }
  188.  
  189.  
  190.     public boolean authenticate(String user, String pword) {
  191.         boolean isValid = false;
  192.         if (user.equalsIgnoreCase("sdevadmin")
  193.                 && pword.equals("460!pass")) {
  194.             isValid = true;
  195.  
  196.  
  197.             try {
  198.                 writer = new BufferedWriter(new FileWriter(filename,append));
  199.                 writer.newLine();
  200.                 writer.append(" Successful login Attempt: " + date + " for " + user);
  201.             }
  202.             // print error message if there is one
  203.             catch (IOException io) {
  204.                 System.out.println("File IO Exception" + io.getMessage());
  205.             }
  206.         }
  207.         else{
  208.             try {
  209.                 writer = new BufferedWriter(new FileWriter(filename, append));
  210.                 writer.newLine();
  211.                 writer.append("Alert! Invalid login attempt on " + date + " for: " + user + " Attempt Number: " + (attempts + 1));
  212.             }
  213.             // print error message if there is one
  214.             catch (IOException io) {
  215.                 System.out.println("File IO Exception" + io.getMessage());
  216.             }
  217.         }
  218.         try {
  219.             if (writer != null) {
  220.                 writer.close();
  221.             }
  222.         }
  223.         //print error message if there is one
  224.         catch (IOException io) {
  225.             System.out.println("Issue closing the File." + io.getMessage());
  226.         }
  227.         return isValid;
  228.         }
  229.  
  230.  
  231.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top