PasswordGenerator is a JavaFX application for generating random text that may be used for passwords. It can also be used for more esoteric purposes such as generating random permutations of digits.
PasswordGenerator has the following features:
SecureRandom
class is used as the pseudo-random number generator for generating random characters.
CharCategory enumeration.
PasswordGenerator is made available under three licences:
uk.blankaspect.passwordgenerator package (including
resources) may be used under the terms and conditions of version 3 of the GNU General Public
License.
This section assumes that you have some experience of building and running a Java application.
The following software is required to build PasswordGenerator:
javafx.base
javafx.controls
javafx.graphics
javafx.swing
The src directory of the blankaspect/passwordGenerator
repository contains the source code and resources that constitute the application; there
are no external dependencies apart from JavaFX. The directory conforms to the Maven
standard directory layout: the source code is in src/main/java and the
resources are in src/main/resources.
The supplied Kotlin-DSL-based Gradle
build script, build.gradle.kts, modifies the compileJava and
jar tasks (provided by the java plug-in) to compile the
application and to create an executable JAR file for it. The compileJava
task expects the required JavaFX modules to be supplied by a JavaFX SDK whose location
is specified by the JAVAFX_HOME environment variable. If this is
unsuitable, you could modify the build script in one of the following ways:
A Java Runtime Environment (JRE) and the JavaFX modules listed above are required to run PasswordGenerator. A Java Development Kit (JDK) includes a JRE. The JavaFX modules may be provided by separate JAR files or they may be included in a JRE:
--module-path and --add-modules options on the command line
of the Java launcher.
jlink tool from a JDK to create a
JRE that contains a custom set of Java SE, JDK and JavaFX modules. The blankaspect/makejre repository
contains a Bash script and a PowerShell 7 script that may be used to create a JRE with
jlink.
The supplied Kotlin-DSL-based Gradle build script, build.gradle.kts,
defines four tasks that may be used to run PasswordGenerator:
runMain and runJar tasks require the JavaFX modules to
be supplied by a JavaFX SDK whose location is specified by the
JAVAFX_HOME environment variable.
runMainJre and runJarJre tasks require a JRE that
includes JavaFX modules. The tasks expect the location of the JRE to be specified by
the JRE_DIR environment variable.
compileJava task.
compileJava task. The class is run with a Java launcher from a JRE that
includes JavaFX modules.
jar task.
jar task. The JAR is
run with a Java launcher from a JRE that includes JavaFX modules.
All four tasks extend the JavaExec task.
When it starts up, PasswordGenerator is configured from an optional configuration file
named passwordGenerator-config.json whose location may be specified
explicitly or implicitly. The configuration file is a text file in JSON (JavaScript
Object Notation) format that is laid out to make it easy for humans to read. A default
value is used for a property that isn't explicitly defined in the configuration
file.
The location and use of a configuration file are controlled by two system properties:
blankaspect.app.auxDir
blankaspect.app.noConfigFile
The system properties may be set on the command line of the Java launcher
(java or javaw) with the -D option.
blankaspect.app.auxDir system property
The blankaspect.app.auxDir system property specifies, explicitly or
implicitly, the directory that contains the configuration file.
blankaspect.app.auxDir system property is an empty
string, PasswordGenerator will look for a configuration file in the current working
directory, which depends on the system and the way in which the application was run.
(On Unix-like systems, the working directory is denoted by the environment variable
PWD.)
blankaspect.app.auxDir system property is not an
empty string, it will be taken as the location of a directory that contains a
configuration file. If the location denotes an existing directory,
PasswordGenerator will look for a configuration file in that directory.
blankaspect.app.auxDir system property does not exist,
PasswordGenerator will look for a configuration file in the default directory:
$HOME/.blankaspect/passwordGenerator, where HOME is the
environment variable that denotes the user's home directory.
%APPDATA%\blankaspect\passwordGenerator, where APPDATA
is an environment variable that denotes a subdirectory of the user's home
directory named AppData.
After the location of the directory is determined in the way described above, if the directory does not exist or it does not contain a configuration file, default values will be used for the configuration properties.
If the configuration has changed when you exit the application normally (ie, using the
Exit command or an equivalent), the
configuration will be written to a configuration file unless the writing of the file is
suppressed by the blankaspect.app.noConfigFile system
property. If the writing of a configuration file is allowed, a file will be written
to the directory whose location is determined in the way described above.
blankaspect.app.noConfigFile system property
If the system property blankaspect.app.noConfigFile exists and its value is
true, no configuration file will be read when PasswordGenerator starts up,
default values will be used for the configuration properties and no configuration file
will be written when the application terminates.
PasswordGenerator's main window is divided into four sections, from top to bottom:
The toolbar contains three buttons, from left to right:
The control pane contains components that control the generation of a password.
At the top of the control pane, there is a pair of check boxes for each of five character categories; each pair comprises a category check box and a category required check box. The categories are associated with disjoint subsets of the ASCII character encoding; taken together, they cover the 95 printable characters of the encoding. The category check box determines whether the characters that belong to the category will be included in the pool from which the characters of a password are drawn. If the category required check box is selected, a generated password must contain at least one character from the corresponding category.
Characters in the Include text field are added to the pool from which the characters of a password are drawn. If the associated Required check box is selected, a generated password must contain at least one of the characters from the field. If any included character is a duplicate of a character from a selected category, the character is removed from the characters that are contributed by the category so that each character in the pool has the same probability of being drawn.
By default, you can include only printable ASCII characters (Unicode code points in the range from U+0020 to U+007E inclusive). This restriction is controlled by a user preference.
Characters in the Exclude text field are removed from the the pool from which the characters of a password are drawn.
If the Unique characters check box is selected, a generated password will not contain any duplicate characters. This requirement implicitly limits the length of a password to the number of characters in the pool from which the characters of a password are drawn.
The Length spinners determine the lower and upper bounds of the length of a generated password. The link button links and unlinks the values of the two spinners. If the spinners are linked, the length of a password will be the value of both spinners. If the spinners are unlinked, the length of a password will be a random value between the lower and upper bounds (inclusive), and all values are equally likely.
The password pane contains a label in which a password is displayed after it has been generated. If a password is too long for the label, it is truncated and the missing part is replaced by an ellipsis. In this case, you can view the whole password — or, at least, as much of it as can fit in the width of the screen — by holding down the primary mouse button on the label.
The button pane contains three buttons, from left to right:
The application's commands may be issued from a button in the toolbar or button pane of the main window or from an item in the Presets menu. Most of the commands may also be issued with a key combination.
The Add or update preset command (Ctrl+P) displays a modal dialog for the name of the preset.
The Edit presets command (Ctrl+E) is available from the Presets menu. It displays a modal dialog that contains a list view of the names of the presets and some buttons for performing operations on the preset that is selected in the list view:
The Preferences command (F8) displays a modal dialog in which the user preferences of PasswordGenerator can be edited. By default, the preferences are stored in a configuration file. The use of a configuration file can be disabled.
The Copy password command (Ctrl+C) copies the last password to be generated by the Generate password command to the system clipboard. The last password is the one that is displayed in the password pane of the main window.
The Generate password command (Ctrl+G) generates a password with the parameters that are obtained from the components in the control pane of the main window. An error message is displayed if the parameters do not allow a password of the desired length to be generated. If a password is generated successfully, it is displayed in the password pane.
The Exit command terminates the application.
The user preferences of PasswordGenerator may be edited in the Preferences dialog that is displayed in response to the Preferences command.
The Colour scheme spinner selects the colour scheme — light or dark — that applies to the user interface of the application. When you change the value in the spinner, the new colour scheme takes effect immediately. The old scheme is restored if you cancel the Preferences dialog.
The Include only ASCII characters check box applies to the characters in the Include field of the main window, which are referred to as included characters. If the check box is selected, an included character must be a printable ASCII character (a Unicode code point in the range from U+0020 to U+007E inclusive); otherwise, an included character may be any character that you can type in the Include field.
The check boxes in the Saved settings pane control whether the state of components in the control pane of the main window will be saved to the configuration file when the application terminates, unless the use of a configuration file has been disabled.
If the Save character parameters check box is selected, the state of the character-related components of the main window will be saved to the configuration file when the application terminates. The character-related components are those whose states correspond to the parameters of a preset.
If the Save password length check box is selected, the values of the Length spinners and the selected state of the link button will be saved to the configuration file when the application terminates.
A preset is a named set of parameters that correspond to the following states of components in the control pane of the main window:
A preset is created with the Add or update preset command. The new preset is added to a list that may be edited with the Edit presets command. When PasswordGenerator terminates, the list of presets is saved to the configuration file unless the use of a configuration file has been disabled.
The names of the current presets are displayed in a menu that is triggered by the Presets button in the toolbar of the main window. If a preset is selected from the menu, the states of the relevant components in the control pane of the main window are updated from the parameters of the preset.
You can update an existing preset with the current state of the components in the control pane by issuing the Add or update preset command and choosing the name of the preset from the drop-down list.
You can perform the following operations from the dialog that is displayed in response to the Edit presets command:
Where indicated elsewhere in this document, some pathname parameters and system properties in PasswordGenerator can contain special constructs for system properties, environment variables and the user's home directory. The special constructs are expanded when the pathname is used.
Java system properties (eg, the user's home directory, user.home) and
environment variables (eg, PATH) are referenced by enclosing them between
${ and }; that is, they must have the form
${<name>}. A Java system property takes precedence over an
environment variable with the same name.
• Example: ${user.home}/projects
• Example: ${HOME}/projects
A Java system property can be specified by prefixing sys. to it:
• Example: ${sys.user.home}/projects
An environment variable can be specified by prefixing env. to it:
• Example: ${env.HOME}/projects
A leading ~ in a pathname is expanded into the user's home directory
using the user.home system property, which is usually equivalent to the
environment variable HOME on Unix-like systems or USERPROFILE
on Windows systems.
• Example: ~/projects
PasswordGenerator recognises the system properties listed below. A system property can
be set on the command line of the Java launcher (java or
javaw) with the -D option (eg,
-Dblankaspect.app.noConfigFile=true).
true, the style sheets that are generated by StyleManager
will be written to a temporary file; otherwise, the style sheets will be data-scheme
URIs.
SimpleDialog is displayed. The delays are applied in the order
size – location – opacity.
Most of the system properties listed above are delays that have been introduced as a workaround for a persistent problem in JavaFX that has been observed on Linux/GNOME when the size or location of a window is changed after it first appears. The default values for the delays have been chosen in a trade-off between two kinds of poor user experience: the shrinking of a window, which is the observable symptom of the problem, versus the unpleasant visual effect of moving the window after it has appeared on the screen. The default values were determined by experiment on a single machine running Ubuntu. They may not be appropriate for other machines and systems, so the delays have been exposed as system properties so that users can modify them. The property values are expected to be integers and the units are milliseconds.
Although the problem is not present in JavaFX on Windows, the same set of delays are applied to simplify the code. This was deemed acceptable because the unpleasant effect of moving a visible window is avoided by setting the opacity of the window to 0 before it is shown, then setting the opacity to 1 after the size and location of the window have been changed. Sadly, the same trick doesn't work on Linux/GNOME because it seems that GNOME doesn't allow the opacity of a window to be changed.