mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-20 19:51:27 +00:00
using constructor-injection, organized imports, code autoformatting [ci skip]
This commit is contained in:
@@ -12,21 +12,11 @@ package org.cryptomator.ui.controllers;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import com.nulabinc.zxcvbn.Strength;
|
||||
import com.nulabinc.zxcvbn.Zxcvbn;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.cryptomator.crypto.engine.InvalidPassphraseException;
|
||||
import org.cryptomator.crypto.engine.UnsupportedVaultFormatException;
|
||||
import org.cryptomator.ui.controls.SecPasswordField;
|
||||
@@ -40,12 +30,16 @@ import org.slf4j.LoggerFactory;
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.binding.BooleanBinding;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Hyperlink;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
import javafx.scene.text.Text;
|
||||
|
||||
@Singleton
|
||||
@@ -54,19 +48,18 @@ public class ChangePasswordController extends LocalizedFXMLViewController {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ChangePasswordController.class);
|
||||
|
||||
private final Application app;
|
||||
private final PasswordStrengthUtil strengthRater;
|
||||
final ObjectProperty<Vault> vault = new SimpleObjectProperty<>();
|
||||
private Optional<ChangePasswordListener> listener = Optional.empty();
|
||||
final IntegerProperty passwordStrength = new SimpleIntegerProperty(); // 0-4
|
||||
private final IntegerProperty passwordStrength = new SimpleIntegerProperty(); // 0-4
|
||||
|
||||
@Inject
|
||||
public ChangePasswordController(Application app, Localization localization) {
|
||||
public ChangePasswordController(Application app, PasswordStrengthUtil strengthRater, Localization localization) {
|
||||
super(localization);
|
||||
this.app = app;
|
||||
this.strengthRater = strengthRater;
|
||||
}
|
||||
|
||||
@Inject
|
||||
PasswordStrengthUtil strengthRater;
|
||||
|
||||
@FXML
|
||||
private SecPasswordField oldPasswordField;
|
||||
|
||||
|
||||
@@ -9,16 +9,15 @@
|
||||
******************************************************************************/
|
||||
package org.cryptomator.ui.controllers;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.binding.BooleanBinding;
|
||||
import javafx.beans.property.*;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.cryptomator.ui.controls.SecPasswordField;
|
||||
import org.cryptomator.ui.model.Vault;
|
||||
import org.cryptomator.ui.settings.Localization;
|
||||
@@ -27,35 +26,34 @@ import org.fxmisc.easybind.EasyBind;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.nulabinc.zxcvbn.*;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.binding.BooleanBinding;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
|
||||
@Singleton
|
||||
public class InitializeController extends LocalizedFXMLViewController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(InitializeController.class);
|
||||
|
||||
private final PasswordStrengthUtil strengthRater;
|
||||
final ObjectProperty<Vault> vault = new SimpleObjectProperty<>();
|
||||
private Optional<InitializationListener> listener = Optional.empty();
|
||||
final IntegerProperty passwordStrength = new SimpleIntegerProperty(); // 0-4
|
||||
private final IntegerProperty passwordStrength = new SimpleIntegerProperty(); // 0-4
|
||||
|
||||
@Inject
|
||||
public InitializeController(Localization localization) {
|
||||
public InitializeController(Localization localization, PasswordStrengthUtil strengthRater) {
|
||||
super(localization);
|
||||
this.strengthRater = strengthRater;
|
||||
}
|
||||
|
||||
@Inject
|
||||
PasswordStrengthUtil strengthRater;
|
||||
|
||||
@FXML
|
||||
private SecPasswordField passwordField;
|
||||
|
||||
|
||||
@@ -8,105 +8,106 @@
|
||||
*******************************************************************************/
|
||||
package org.cryptomator.ui.util;
|
||||
|
||||
import com.nulabinc.zxcvbn.Zxcvbn;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.scene.paint.Color;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.cryptomator.ui.settings.Localization;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.cryptomator.ui.settings.Localization;
|
||||
|
||||
import com.nulabinc.zxcvbn.Zxcvbn;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
@Singleton
|
||||
public class PasswordStrengthUtil {
|
||||
|
||||
private final Zxcvbn zxcvbn;
|
||||
private final List<String> sanitizedInputs;
|
||||
private final Localization localization;
|
||||
private final Zxcvbn zxcvbn;
|
||||
private final List<String> sanitizedInputs;
|
||||
private final Localization localization;
|
||||
|
||||
@Inject
|
||||
public PasswordStrengthUtil(Localization localization){
|
||||
this.localization = localization;
|
||||
this.zxcvbn = new Zxcvbn();
|
||||
this.sanitizedInputs = new ArrayList<>();
|
||||
this.sanitizedInputs.add("cryptomator");
|
||||
}
|
||||
@Inject
|
||||
public PasswordStrengthUtil(Localization localization) {
|
||||
this.localization = localization;
|
||||
this.zxcvbn = new Zxcvbn();
|
||||
this.sanitizedInputs = new ArrayList<>();
|
||||
this.sanitizedInputs.add("cryptomator");
|
||||
}
|
||||
|
||||
public int computeRate(String password) {
|
||||
if (StringUtils.isEmpty(password)) {
|
||||
return -1;
|
||||
} else {
|
||||
return zxcvbn.measure(password, sanitizedInputs).getScore();
|
||||
}
|
||||
}
|
||||
public int computeRate(String password) {
|
||||
if (StringUtils.isEmpty(password)) {
|
||||
return -1;
|
||||
} else {
|
||||
return zxcvbn.measure(password, sanitizedInputs).getScore();
|
||||
}
|
||||
}
|
||||
|
||||
public Color getStrengthColor(Number score) {
|
||||
Color strengthColor = Color.web("#FF0000");
|
||||
switch (score.intValue()) {
|
||||
case 0:
|
||||
strengthColor = Color.web("#FF0000");
|
||||
break;
|
||||
case 1:
|
||||
strengthColor = Color.web("#FF8000");
|
||||
break;
|
||||
case 2:
|
||||
strengthColor = Color.web("#FFBF00");
|
||||
break;
|
||||
case 3:
|
||||
strengthColor = Color.web("#FFFF00");
|
||||
break;
|
||||
case 4:
|
||||
strengthColor = Color.web("#BFFF00");
|
||||
break;
|
||||
default:
|
||||
strengthColor = Color.web("#FF0000");
|
||||
break;
|
||||
}
|
||||
return strengthColor;
|
||||
}
|
||||
public Color getStrengthColor(Number score) {
|
||||
Color strengthColor = Color.web("#FF0000");
|
||||
switch (score.intValue()) {
|
||||
case 0:
|
||||
strengthColor = Color.web("#FF0000");
|
||||
break;
|
||||
case 1:
|
||||
strengthColor = Color.web("#FF8000");
|
||||
break;
|
||||
case 2:
|
||||
strengthColor = Color.web("#FFBF00");
|
||||
break;
|
||||
case 3:
|
||||
strengthColor = Color.web("#FFFF00");
|
||||
break;
|
||||
case 4:
|
||||
strengthColor = Color.web("#BFFF00");
|
||||
break;
|
||||
default:
|
||||
strengthColor = Color.web("#FF0000");
|
||||
break;
|
||||
}
|
||||
return strengthColor;
|
||||
}
|
||||
|
||||
public int getWidth(Number score) {
|
||||
int width = 0;
|
||||
switch (score.intValue()) {
|
||||
case 0:
|
||||
width += 5;
|
||||
break;
|
||||
case 1:
|
||||
width += 25;
|
||||
break;
|
||||
case 2:
|
||||
width += 50;
|
||||
break;
|
||||
case 3:
|
||||
width += 75;
|
||||
break;
|
||||
case 4:
|
||||
width = 100;
|
||||
break;
|
||||
default:
|
||||
width = 0;
|
||||
break;
|
||||
}
|
||||
return Math.round(width*2.23f);
|
||||
}
|
||||
public int getWidth(Number score) {
|
||||
int width = 0;
|
||||
switch (score.intValue()) {
|
||||
case 0:
|
||||
width += 5;
|
||||
break;
|
||||
case 1:
|
||||
width += 25;
|
||||
break;
|
||||
case 2:
|
||||
width += 50;
|
||||
break;
|
||||
case 3:
|
||||
width += 75;
|
||||
break;
|
||||
case 4:
|
||||
width = 100;
|
||||
break;
|
||||
default:
|
||||
width = 0;
|
||||
break;
|
||||
}
|
||||
return Math.round(width * 2.23f);
|
||||
}
|
||||
|
||||
public float getStrokeWidth(Number score) {
|
||||
if (score.intValue() >= 0) {
|
||||
return 0.5f;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public float getStrokeWidth(Number score) {
|
||||
if (score.intValue() >= 0) {
|
||||
return 0.5f;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public String getStrengthDescription(Number score) {
|
||||
if (score.intValue() >= 0) {
|
||||
return String.format(localization.getString("initialize.messageLabel.passwordStrength"),
|
||||
localization.getString("initialize.messageLabel.passwordStrength." + score.intValue()));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
public String getStrengthDescription(Number score) {
|
||||
if (score.intValue() >= 0) {
|
||||
return String.format(localization.getString("initialize.messageLabel.passwordStrength"), localization.getString("initialize.messageLabel.passwordStrength." + score.intValue()));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user