Skip to content

Commit

Permalink
bits indicator, shuffle options
Browse files Browse the repository at this point in the history
  • Loading branch information
alexyz committed Sep 28, 2019
1 parent 50c5168 commit c40326a
Show file tree
Hide file tree
Showing 7 changed files with 393 additions and 249 deletions.
19 changes: 0 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,6 @@
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>install</phase>
<configuration>
<target>
<copy todir="${user.home}/Dropbox/Public">
<fileset dir="target" includes="passwordgen.jar" />
</copy>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

</build>
Expand Down
18 changes: 10 additions & 8 deletions src/pwgen/BitsPasswordJPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import javax.swing.*;

import static pwgen.PwUtil.*;

public class BitsPasswordJPanel extends PasswordJPanel {

private final JSpinner bitsSpinner = new JSpinner(new SpinnerNumberModel(8, 8, 4096, 8));
Expand All @@ -20,25 +22,25 @@ public BitsPasswordJPanel () {
protected void loadPrefs () throws Exception {
System.out.println("load prefs");
Preferences prefs = Preferences.userNodeForPackage(getClass());
bitsSpinner.setValue(Integer.valueOf(prefs.getInt("bits", 64)));
b64CheckBox.setSelected(prefs.getBoolean("b64", true));
bitsSpinner.setValue(Integer.valueOf(prefs.getInt("btbits", 64)));
b64CheckBox.setSelected(prefs.getBoolean("btb64", true));
}

@Override
protected void savePrefs () throws Exception {
System.out.println("save prefs");
Preferences prefs = Preferences.userNodeForPackage(getClass());
prefs.putInt("bits", ((Number) bitsSpinner.getValue()).intValue());
prefs.putBoolean("any", b64CheckBox.isSelected());
prefs.putInt("btbits", ((Number) bitsSpinner.getValue()).intValue());
prefs.putBoolean("btb64", b64CheckBox.isSelected());
prefs.flush();
}

@Override
public String generate () {
public void generate () {
StringBuilder sb = new StringBuilder();
int bits = ((Number) bitsSpinner.getValue()).intValue();
sb.append(bits(bits, b64CheckBox.isSelected()));
int b = intValue(bitsSpinner);
sb.append(bits(b, b64CheckBox.isSelected()));
Collections.shuffle(new StringBuilderList(sb), RANDOM);
return sb.toString();
setValue(sb.toString(), Math.pow(2, b));
}
}
54 changes: 36 additions & 18 deletions src/pwgen/CharPasswordJPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@

import javax.swing.*;

import static pwgen.PwUtil.*;

public class CharPasswordJPanel extends PasswordJPanel {

private final JSpinner lowerSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 99, 1));
private final JSpinner upperSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 99, 1));
private final JSpinner digitSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 99, 1));
private final JSpinner punctSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 99, 1));
private final JSpinner anySpinner = new JSpinner(new SpinnerNumberModel(0, 0, 99, 1));
private final JCheckBox shuffleBox = new JCheckBox("Shuffle");


public CharPasswordJPanel () {
optionPanel.add(new JLabel("Upper"));
Expand All @@ -24,40 +28,54 @@ public CharPasswordJPanel () {
optionPanel.add(punctSpinner);
optionPanel.add(new JLabel("Any"));
optionPanel.add(anySpinner);
optionPanel.add(shuffleBox);
}

@Override
protected void loadPrefs () throws Exception {
System.out.println("load prefs");
Preferences prefs = Preferences.userNodeForPackage(getClass());
lowerSpinner.setValue(prefs.getInt("lower", 6));
upperSpinner.setValue(prefs.getInt("upper", 1));
digitSpinner.setValue(prefs.getInt("digitx", 1));
punctSpinner.setValue(prefs.getInt("punct", 0));
anySpinner.setValue(prefs.getInt("any", 0));
lowerSpinner.setValue(prefs.getInt("chlower", 5));
upperSpinner.setValue(prefs.getInt("chupper", 1));
digitSpinner.setValue(prefs.getInt("chdigit", 1));
punctSpinner.setValue(prefs.getInt("chpunct", 1));
anySpinner.setValue(prefs.getInt("chany", 0));
shuffleBox.setSelected(prefs.getBoolean("chshuf", true));
}

@Override
protected void savePrefs () throws Exception {
System.out.println("save prefs");
Preferences prefs = Preferences.userNodeForPackage(getClass());
prefs.putInt("upper", (Integer) upperSpinner.getValue());
prefs.putInt("lower", (Integer) lowerSpinner.getValue());
prefs.putInt("digitx", (Integer) digitSpinner.getValue());
prefs.putInt("punct", (Integer) punctSpinner.getValue());
prefs.putInt("any", (Integer) anySpinner.getValue());
prefs.putInt("chupper", (Integer) upperSpinner.getValue());
prefs.putInt("chlower", (Integer) lowerSpinner.getValue());
prefs.putInt("chdigit", (Integer) digitSpinner.getValue());
prefs.putInt("chpunct", (Integer) punctSpinner.getValue());
prefs.putInt("chany", (Integer) anySpinner.getValue());
prefs.putBoolean("chshuf", shuffleBox.isSelected());
prefs.flush();
}

@Override
public String generate () {
public void generate () {
StringBuilder sb = new StringBuilder();
sb.append(upper((Integer) upperSpinner.getValue()));
sb.append(lower((Integer) lowerSpinner.getValue()));
sb.append(digit((Integer) digitSpinner.getValue()));
sb.append(punct((Integer) punctSpinner.getValue()));
sb.append(any((Integer) anySpinner.getValue()));
Collections.shuffle(new StringBuilderList(sb), RANDOM);
return sb.toString();
int u = intValue(upperSpinner);
int l = intValue(lowerSpinner);
int d = intValue(digitSpinner);
int p = intValue(punctSpinner);
int a = intValue(anySpinner);
sb.append(upper(u));
sb.append(lower(l));
sb.append(digit(d));
sb.append(punct(p));
sb.append(any(a));
double v = pow(26, u + l) + pow(10, d) + pow(PUNCT, p) + pow(ANY, a);
System.out.println("v=" + v);
if (shuffleBox.isSelected()) {
Collections.shuffle(new StringBuilderList(sb), RANDOM);
double f = fac(sb.length()) / (fac(u)*fac(l)*fac(d)*fac(p)*fac(a));
v = v * f;
}
setValue(sb.toString(), v);
}
}
Loading

0 comments on commit c40326a

Please sign in to comment.