Merge remote-tracking branch 'remotes/origin/master' into issue-228-fixed

This commit is contained in:
jncharon
2016-05-05 21:22:28 +02:00
10 changed files with 230 additions and 31 deletions

View File

@@ -254,6 +254,7 @@
<artifactId>hamcrest-all</artifactId>
<version>${hamcrest.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@@ -99,5 +99,12 @@
<groupId>org.cryptomator</groupId>
<artifactId>commons-test</artifactId>
</dependency>
<!-- Zxcvbn -->
<dependency>
<groupId>com.nulab-inc</groupId>
<artifactId>zxcvbn</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</project>

View File

@@ -5,22 +5,35 @@
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
* Jean-Noël Charon - password strength meter
*******************************************************************************/
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;
import org.cryptomator.ui.model.Vault;
import org.cryptomator.ui.settings.Localization;
import org.cryptomator.ui.util.PasswordStrengthUtil;
import org.fxmisc.easybind.EasyBind;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,6 +56,7 @@ public class ChangePasswordController extends LocalizedFXMLViewController {
private final Application app;
final ObjectProperty<Vault> vault = new SimpleObjectProperty<>();
private Optional<ChangePasswordListener> listener = Optional.empty();
final IntegerProperty passwordStrength = new SimpleIntegerProperty(); // 0-4
@Inject
public ChangePasswordController(Application app, Localization localization) {
@@ -50,6 +64,9 @@ public class ChangePasswordController extends LocalizedFXMLViewController {
this.app = app;
}
@Inject
PasswordStrengthUtil strengthRater;
@FXML
private SecPasswordField oldPasswordField;
@@ -68,12 +85,24 @@ public class ChangePasswordController extends LocalizedFXMLViewController {
@FXML
private Hyperlink downloadsPageLink;
@FXML
private Label passwordStrengthLabel;
@FXML
private Rectangle passwordStrengthShape;
@Override
public void initialize() {
BooleanBinding oldPasswordIsEmpty = oldPasswordField.textProperty().isEmpty();
BooleanBinding newPasswordIsEmpty = newPasswordField.textProperty().isEmpty();
BooleanBinding passwordsDiffer = newPasswordField.textProperty().isNotEqualTo(retypePasswordField.textProperty());
changePasswordButton.disableProperty().bind(oldPasswordIsEmpty.or(newPasswordIsEmpty.or(passwordsDiffer)));
passwordStrength.bind(EasyBind.map(newPasswordField.textProperty(), strengthRater::computeRate));
passwordStrengthShape.widthProperty().bind(EasyBind.map(passwordStrength, strengthRater::getWidth));
passwordStrengthShape.fillProperty().bind(EasyBind.map(passwordStrength, strengthRater::getStrengthColor));
passwordStrengthShape.strokeWidthProperty().bind(EasyBind.map(passwordStrength, strengthRater::getStrokeWidth));
passwordStrengthLabel.textProperty().bind(EasyBind.map(passwordStrength, strengthRater::getStrengthDescription));
}
@Override

View File

@@ -2,35 +2,42 @@
* Copyright (c) 2014, 2016 Sebastian Stenzel
* This file is licensed under the terms of the MIT license.
* See the LICENSE.txt file for more info.
*
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
* Jean-Noël Charon - password strength meter
******************************************************************************/
package org.cryptomator.ui.controllers;
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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javafx.application.Platform;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
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 org.cryptomator.ui.controls.SecPasswordField;
import org.cryptomator.ui.model.Vault;
import org.cryptomator.ui.settings.Localization;
import org.cryptomator.ui.util.PasswordStrengthUtil;
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.*;
@Singleton
public class InitializeController extends LocalizedFXMLViewController {
@@ -39,12 +46,16 @@ public class InitializeController extends LocalizedFXMLViewController {
final ObjectProperty<Vault> vault = new SimpleObjectProperty<>();
private Optional<InitializationListener> listener = Optional.empty();
final IntegerProperty passwordStrength = new SimpleIntegerProperty(); // 0-4
@Inject
public InitializeController(Localization localization) {
super(localization);
}
@Inject
PasswordStrengthUtil strengthRater;
@FXML
private SecPasswordField passwordField;
@@ -57,11 +68,23 @@ public class InitializeController extends LocalizedFXMLViewController {
@FXML
private Label messageLabel;
@FXML
private Label passwordStrengthLabel;
@FXML
private Rectangle passwordStrengthShape;
@Override
public void initialize() {
BooleanBinding passwordIsEmpty = passwordField.textProperty().isEmpty();
BooleanBinding passwordsDiffer = passwordField.textProperty().isNotEqualTo(retypePasswordField.textProperty());
okButton.disableProperty().bind(passwordIsEmpty.or(passwordsDiffer));
passwordStrength.bind(EasyBind.map(passwordField.textProperty(), strengthRater::computeRate));
passwordStrengthShape.widthProperty().bind(EasyBind.map(passwordStrength, strengthRater::getWidth));
passwordStrengthShape.fillProperty().bind(EasyBind.map(passwordStrength, strengthRater::getStrengthColor));
passwordStrengthShape.strokeWidthProperty().bind(EasyBind.map(passwordStrength, strengthRater::getStrokeWidth));
passwordStrengthLabel.textProperty().bind(EasyBind.map(passwordStrength, strengthRater::getStrengthDescription));
}
@Override

View File

@@ -154,6 +154,7 @@ public class WelcomeController extends LocalizedFXMLViewController {
Platform.runLater(() -> {
this.updateLink.setText(msg);
this.updateLink.setVisible(true);
this.updateLink.setDisable(false);
});
}
}

View File

@@ -0,0 +1,112 @@
/*******************************************************************************
* Copyright (c) 2016 Sebastian Stenzel and others.
* This file is licensed under the terms of the MIT license.
* See the LICENSE.txt file for more info.
*
* Contributors:
* Jean-Noël Charon - initial API and implementation
*******************************************************************************/
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 javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
@Singleton
public class PasswordStrengthUtil {
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");
}
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 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 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 "";
}
}
}

View File

@@ -6,6 +6,7 @@
Contributors:
Sebastian Stenzel - initial API and implementation
Jean-Noël Charon - password strength meter
-->
<?import java.net.URL?>
<?import java.lang.String?>
@@ -22,6 +23,7 @@
<?import javafx.scene.text.Text?>
<?import javafx.scene.shape.Rectangle?>
<GridPane vgap="12.0" hgap="12.0" prefWidth="400.0" xmlns:fx="http://javafx.com/fxml" cacheShape="true" cache="true">
<padding>
<Insets top="24.0" right="12.0" bottom="24.0" left="12.0" />
@@ -44,12 +46,18 @@
<!-- Row 2 -->
<Label text="%changePassword.label.retypePassword" GridPane.rowIndex="2" GridPane.columnIndex="0" cacheShape="true" cache="true" />
<SecPasswordField fx:id="retypePasswordField" GridPane.rowIndex="2" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" maxWidth="Infinity" cacheShape="true" cache="true" />
<!-- Row 3 -->
<Button fx:id="changePasswordButton" text="%changePassword.button.change" defaultButton="true" GridPane.rowIndex="3" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.halignment="RIGHT" prefWidth="150.0" onAction="#didClickChangePasswordButton" disable="true" cacheShape="true" cache="true"/>
<Label fx:id="passwordStrengthLabel" cache="true" cacheShape="true" text="" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<!-- Row 4 -->
<TextFlow GridPane.rowIndex="4" GridPane.columnIndex="0" GridPane.columnSpan="2" cacheShape="true" cache="true">
<Rectangle fx:id="passwordStrengthShape" width="0" height="15" GridPane.columnIndex="1" GridPane.rowIndex="4" fill="#FF0000" stroke="grey" strokeWidth="0" />
<!-- Row 5 -->
<Button fx:id="changePasswordButton" text="%changePassword.button.change" defaultButton="true" GridPane.rowIndex="5" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.halignment="RIGHT" prefWidth="150.0" onAction="#didClickChangePasswordButton" disable="true" cacheShape="true" cache="true"/>
<!-- Row 6 -->
<TextFlow GridPane.rowIndex="6" GridPane.columnIndex="5" GridPane.columnSpan="2" cacheShape="true" cache="true">
<children>
<Text fx:id="messageText" cache="true" />
<Hyperlink fx:id="downloadsPageLink" text="%changePassword.label.downloadsPageLink" visible="false" onAction="#didClickDownloadsLink" cacheShape="true" cache="true" />

View File

@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2014 Sebastian Stenzel
This file is licensed under the terms of the MIT license.
@@ -6,15 +7,21 @@
Contributors:
Sebastian Stenzel - initial API and implementation
Jean-Noël Charon - password strength meter
-->
<?import java.lang.*?>
<?import java.net.URL?>
<?import javafx.scene.layout.HBox?>
<?import org.cryptomator.ui.controls.SecPasswordField?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.control.ProgressIndicator?>
<?import org.cryptomator.ui.controls.SecPasswordField?>
<?import javafx.scene.shape.Rectangle?>
<GridPane vgap="12.0" hgap="12.0" prefWidth="400.0" xmlns:fx="http://javafx.com/fxml" cacheShape="true" cache="true">
<padding>
@@ -30,17 +37,22 @@
<!-- Row 0 -->
<Label GridPane.rowIndex="0" GridPane.columnIndex="0" text="%initialize.label.password" cacheShape="true" cache="true" />
<SecPasswordField fx:id="passwordField" GridPane.rowIndex="0" GridPane.columnIndex="1" cacheShape="true" cache="true" />
<!-- Row 1 -->
<Label GridPane.rowIndex="1" GridPane.columnIndex="0" text="%initialize.label.retypePassword" cacheShape="true" cache="true" />
<SecPasswordField fx:id="retypePasswordField" GridPane.rowIndex="1" GridPane.columnIndex="1" cacheShape="true" cache="true" />
<!-- Row 2 -->
<Button fx:id="okButton" defaultButton="true" GridPane.rowIndex="2" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.halignment="RIGHT" text="%initialize.button.ok" prefWidth="150.0" onAction="#initializeVault" focusTraversable="false" disable="true" cacheShape="true" cache="true" />
<Label fx:id="passwordStrengthLabel" cache="true" cacheShape="true" text="" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<!-- Row 2 -->
<Rectangle fx:id="passwordStrengthShape" width="0" height="15" GridPane.columnIndex="1" GridPane.rowIndex="3" fill="#FF0000" stroke="grey" strokeWidth="0" />
<!-- Row 3 -->
<Label fx:id="messageLabel" GridPane.rowIndex="3" GridPane.columnIndex="0" GridPane.columnSpan="2" cacheShape="true" cache="true" />
<Button fx:id="okButton" cache="true" cacheShape="true" defaultButton="true" disable="true" focusTraversable="false" onAction="#initializeVault" prefWidth="150.0" text="%initialize.button.ok" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.halignment="RIGHT" GridPane.rowIndex="4" />
<!-- Row 4 -->
<Label fx:id="messageLabel" cache="true" cacheShape="true" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="5" />
</children>
</GridPane>

View File

@@ -25,7 +25,7 @@
<Label fx:id="checkForUpdatesStatus" cacheShape="true" cache="true" />
<ProgressIndicator fx:id="checkForUpdatesIndicator" progress="-1" prefWidth="15.0" prefHeight="15.0" cacheShape="true" cache="true" cacheHint="SPEED" />
</HBox>
<Hyperlink alignment="CENTER" fx:id="updateLink" onAction="#didClickUpdateLink" cacheShape="true" cache="true" />
<Hyperlink alignment="CENTER" fx:id="updateLink" onAction="#didClickUpdateLink" cacheShape="true" cache="true" disable="true" />
</VBox>
<ImageView fitHeight="200.0" preserveRatio="true" smooth="false" cache="true" style="-fx-background-color: green;">

View File

@@ -27,6 +27,12 @@ initialize.label.retypePassword=Retype password
initialize.button.ok=Create vault
initialize.messageLabel.alreadyInitialized=Vault already initialized
initialize.messageLabel.initializationFailed=Could not initialize vault. See logfile for details.
initialize.messageLabel.passwordStrength=Password Strength: %s
initialize.messageLabel.passwordStrength.0=Weak
initialize.messageLabel.passwordStrength.1=Fair
initialize.messageLabel.passwordStrength.2=Good
initialize.messageLabel.passwordStrength.3=Strong
initialize.messageLabel.passwordStrength.4=Very strong
# notfound.fxml
notfound.label=Vault couldn't be found. Has it been moved?