Skip to content

Commit

Permalink
version 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
user9209 committed Dec 9, 2018
1 parent e9d73c0 commit d994efb
Show file tree
Hide file tree
Showing 11 changed files with 361 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Password-Strength.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/resources" type="java-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
9 changes: 8 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ password in the binary system and its bit strength.
- 21 chars ≈ 128 bit
- 41 chars ≈ 256 bit

As you can see special chars do not help much.
As you can see special chars do not help much.

## Version Releases
- **Version 0.1**
- cli only
- **Version 0.2**
- GUI JavaFX added

3 changes: 3 additions & 0 deletions src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: de.gs_sys.gui.jfx.FXstarter

51 changes: 51 additions & 0 deletions src/de/gs_sys/gui/jfx/AppFX.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright (C) 2017, 2018 Georg Schmidt <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.gs_sys.gui.jfx;

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

public class AppFX extends Application {

public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage stage) throws Exception {
// ignores the given stage !

/* create and setup main stage */
Stage mainStage = StageCreator.getStageFromFXML("Password Gen","gui.fxml");

/* Load hotkeys */
ControllerMain.loadHotkeys(mainStage);

// Close App on X (Needs to be AFTER addStage() to overwrite default close)
mainStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
System.exit(0);
}
});

// No resize
mainStage.setResizable(false);
}
}
101 changes: 101 additions & 0 deletions src/de/gs_sys/gui/jfx/ControllerMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
Copyright (C) 2017, 2018 Georg Schmidt <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.gs_sys.gui.jfx;

import de.gs_sys.lib.crypto.passwords.PasswordStrength;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
;
import java.net.URL;

import java.util.ResourceBundle;


public class ControllerMain implements Initializable {


private final String versionString = "V 0.2 fx";

private static ControllerMain instance;

@FXML
private TextField password_field;

@FXML
private Button b_version;

@FXML
private Label passwordQuality;

@FXML
private Button button_check;

@FXML
void onButtonVersion() {
password_field.setText("Copyright (c) 2018 Georg Schmidt");
}

@FXML
private void onCheck() {

setQuality(password_field.getText());
}

private void setQuality(String password) {
passwordQuality.setText("Corresponds to " + PasswordStrength.complexity(password).getBit() + " bit.");
}

@Override
public void initialize(URL location, ResourceBundle resources) {
instance = this;

// disables most console output
PasswordStrength.setCli(false);

b_version.setText(versionString);

password_field.textProperty().addListener((obs, oldValue, newValue) -> onCheck());

// Default in button
Platform.runLater(() -> button_check.requestFocus());
}

/**
* Registers the hotkeys
*/
public static void loadHotkeys(Stage stage)
{
stage.getScene().setOnKeyReleased(keyEvent1 -> {
switch (keyEvent1.getCode())
{
case ESCAPE:
System.exit(0);
break;
case ENTER:
instance.onCheck();
break;
default:
}
});
}
}
41 changes: 41 additions & 0 deletions src/de/gs_sys/gui/jfx/FXstarter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright (C) 2017, 2018 Georg Schmidt <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.gs_sys.gui.jfx;


import de.gs_sys.lib.crypto.passwords.PasswordStrength;

public class FXstarter {
public static void main(String[] args) {

// force old version
if(args.length == 1 && args[0].equals("-old"))
{
System.err.println("Needs to support JavaFX8!");
PasswordStrength.main(args);
}

try {
FXstarter.class.getClassLoader().loadClass("javafx.application.Application");
AppFX.main(args);
} catch (ClassNotFoundException e) {
System.err.println("Needs to support JavaFX8!");
PasswordStrength.main(args);
}
}
}
66 changes: 66 additions & 0 deletions src/de/gs_sys/gui/jfx/StageCreator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright (C) 2017, 2018 Georg Schmidt <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.gs_sys.gui.jfx;

import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.io.IOException;

/**
* Creates JavaFX sage from a fxml file
*/
public class StageCreator {

/**
* Opens a .fxml file and returns a stage using this file and the given title
* @param title Title of the window
* @param file .fxml file with the window configuration
* @return stage out of the fxml file
*/
@SuppressWarnings("ConstantConditions")
public static Stage getStageFromFXML(String title, String file)
{
if(file == null || file.isEmpty())
return null;

// create new stage
Stage newStage = new Stage(StageStyle.DECORATED); // normal window

// set title if exist
if(title != null && !title.isEmpty())
newStage.setTitle(title);

try {
// create new scene
BorderPane root = FXMLLoader.load(StageCreator.class.getClassLoader().getResource(file));
Scene scene = new Scene(root);

/* final stage setup */
newStage.setScene(scene);
newStage.show();
return newStage;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
12 changes: 10 additions & 2 deletions src/de/gs_sys/lib/crypto/passwords/PasswordStrength.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

public class PasswordStrength {

private static boolean cli = true;

public static void setCli(boolean cli) {
PasswordStrength.cli = cli;
}

/**
* Demo Main
*/
Expand Down Expand Up @@ -103,8 +109,10 @@ public static Complexity complexity(String password) {
complexity.setLength(password.length());
complexity.setBit(bitStrength(chars, complexity.getLength()));

System.out.print(chars + " chars ^ " + complexity.getLength() + " length \u2248 ");
System.out.println(complexity.getBit() + " bit");
if(PasswordStrength.cli) {
System.out.print(chars + " chars ^ " + complexity.getLength() + " length \u2248 ");
System.out.println(complexity.getBit() + " bit");
}

return complexity;
}
Expand Down
55 changes: 55 additions & 0 deletions src/resources/gui.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="131.0" prefWidth="321.0" xmlns="http://javafx.com/javafx/8.0.161-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.gs_sys.gui.jfx.ControllerMain">
<center>
<VBox prefHeight="108.0" prefWidth="321.0" BorderPane.alignment="CENTER">
<children>
<TextField fx:id="password_field" alignment="CENTER">
<VBox.margin>
<Insets bottom="5.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
<font>
<Font size="18.0" />
</font>
</TextField>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<children>
<Button fx:id="button_check" maxWidth="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#onCheck" text="Check">
<HBox.margin>
<Insets bottom="5.0" right="10.0" top="5.0" />
</HBox.margin>
</Button>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<children>
<Button fx:id="b_version" maxWidth="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#onButtonVersion" prefWidth="80.0" text="V xx fx">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
<font>
<Font size="12.0" />
</font>
</Button>
<Label fx:id="passwordQuality" alignment="CENTER" contentDisplay="CENTER" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="200.0" text="QUALITY" textAlignment="CENTER">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Label>
<AnchorPane prefHeight="200.0" prefWidth="200.0" />
</children>
</HBox>
</children>
</VBox>
</center>
</BorderPane>

0 comments on commit d994efb

Please sign in to comment.