added zxcvbn password score (#199)

* added zxcvbn password score

* changes messages & thresholds

change password label to passphrase
This commit is contained in:
m2049r 2018-02-23 19:32:21 +01:00 committed by GitHub
parent 2db36bb824
commit 88bc33b5a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 4 deletions

View File

@ -59,6 +59,8 @@ dependencies {
compile "com.squareup.okhttp3:okhttp:$rootProject.ext.okHttpVersion" compile "com.squareup.okhttp3:okhttp:$rootProject.ext.okHttpVersion"
compile "com.jakewharton.timber:timber:$rootProject.ext.timberVersion" compile "com.jakewharton.timber:timber:$rootProject.ext.timberVersion"
compile 'com.nulab-inc:zxcvbn:1.2.3'
testCompile "junit:junit:$rootProject.ext.junitVersion" testCompile "junit:junit:$rootProject.ext.junitVersion"
testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion" testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion"
testCompile "com.squareup.okhttp3:mockwebserver:$rootProject.ext.okHttpVersion" testCompile "com.squareup.okhttp3:mockwebserver:$rootProject.ext.okHttpVersion"

View File

@ -21,7 +21,9 @@ import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.TextInputLayout; import android.support.design.widget.TextInputLayout;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.InputType; import android.text.InputType;
import android.text.TextWatcher;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -37,6 +39,8 @@ import com.m2049r.xmrwallet.widget.Toolbar;
import com.m2049r.xmrwallet.model.Wallet; import com.m2049r.xmrwallet.model.Wallet;
import com.m2049r.xmrwallet.model.WalletManager; import com.m2049r.xmrwallet.model.WalletManager;
import com.m2049r.xmrwallet.util.Helper; import com.m2049r.xmrwallet.util.Helper;
import com.nulabinc.zxcvbn.Strength;
import com.nulabinc.zxcvbn.Zxcvbn;
import java.io.File; import java.io.File;
import java.text.ParseException; import java.text.ParseException;
@ -129,7 +133,7 @@ public class GenerateFragment extends Fragment {
}); });
Helper.showKeyboard(getActivity()); Helper.showKeyboard(getActivity());
//##############
etWalletName.getEditText().setOnEditorActionListener(new TextView.OnEditorActionListener() { etWalletName.getEditText().setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_NEXT)) { if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_NEXT)) {
@ -256,11 +260,61 @@ public class GenerateFragment extends Fragment {
} }
}); });
etWalletPassword.getEditText().addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable editable) {
checkPassword();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
etWalletName.requestFocus(); etWalletName.requestFocus();
initZxcvbn();
return view; return view;
} }
Zxcvbn zxcvbn = new Zxcvbn();
// initialize zxcvbn engine in background thread
private void initZxcvbn() {
new Thread(new Runnable() {
@Override
public void run() {
zxcvbn.measure("");
}
}).start();
}
private void checkPassword() {
String password = etWalletPassword.getEditText().getText().toString();
if (!password.isEmpty()) {
Strength strength = zxcvbn.measure(password);
int msg;
double guessesLog10 = strength.getGuessesLog10();
if (guessesLog10 < 10)
msg = R.string.password_weak;
else if (guessesLog10 < 11)
msg = R.string.password_fair;
else if (guessesLog10 < 12)
msg = R.string.password_good;
else if (guessesLog10 < 13)
msg = R.string.password_strong;
else
msg = R.string.password_very_strong;
etWalletPassword.setError(getResources().getString(msg));
} else {
etWalletPassword.setError(null);
}
}
private boolean checkName() { private boolean checkName() {
String name = etWalletName.getEditText().getText().toString(); String name = etWalletName.getEditText().getText().toString();
boolean ok = true; boolean ok = true;

View File

@ -113,7 +113,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_marginBottom="88dp" android:layout_marginBottom="88dp"
android:layout_marginEnd="16dp"> android:layout_marginEnd="16dp"
android:background="?android:attr/selectableItemBackgroundBorderless">
<TextView <TextView
android:id="@+id/fabSeedT" android:id="@+id/fabSeedT"

View File

@ -13,6 +13,12 @@
<string name="menu_archive">Archivar</string> <string name="menu_archive">Archivar</string>
<string name="menu_backup">Copia de seguridad</string> <string name="menu_backup">Copia de seguridad</string>
<string name="password_weak">Sigue escribiendo &#8230;</string>
<string name="password_fair">Mas o menos.</string>
<string name="password_good">Puedes hacerlo mejor.</string>
<string name="password_strong">Casi &#8230;</string>
<string name="password_very_strong">¡Bien ahí, hacker nivel 4!</string>
<string name="label_login_wallets">Monederos</string> <string name="label_login_wallets">Monederos</string>
<string name="label_donate">Donar</string> <string name="label_donate">Donar</string>
<string name="label_ok">Aceptar</string> <string name="label_ok">Aceptar</string>
@ -126,7 +132,7 @@
<string name="generate_title">Crear monedero</string> <string name="generate_title">Crear monedero</string>
<string name="generate_name_hint">Nombre del monedero</string> <string name="generate_name_hint">Nombre del monedero</string>
<string name="generate_password_hint">Contraseña del monedero</string> <string name="generate_password_hint">Frase de Contraseña</string>
<string name="generate_buttonGenerate">¡Házme ya un monedero!</string> <string name="generate_buttonGenerate">¡Házme ya un monedero!</string>
<string name="generate_seed">Semilla Mnemotécnica</string> <string name="generate_seed">Semilla Mnemotécnica</string>
<string name="generate_button_accept">¡He apuntado estas 25 palabras!</string> <string name="generate_button_accept">¡He apuntado estas 25 palabras!</string>

View File

@ -15,6 +15,12 @@
<string name="menu_archive">Archive</string> <string name="menu_archive">Archive</string>
<string name="menu_backup">Backup</string> <string name="menu_backup">Backup</string>
<string name="password_weak">Continue typing &#8230;</string>
<string name="password_fair">Meh &#8230;</string>
<string name="password_good">C\'mon, you can do better!</string>
<string name="password_strong">Getting there &#8230;</string>
<string name="password_very_strong">Yeah baby, h4x0r style!</string>
<string name="label_login_wallets">Wallets</string> <string name="label_login_wallets">Wallets</string>
<string name="label_donate">Donate</string> <string name="label_donate">Donate</string>
<string name="label_ok">OK</string> <string name="label_ok">OK</string>
@ -197,7 +203,7 @@
<string name="generate_title">Create Wallet</string> <string name="generate_title">Create Wallet</string>
<string name="generate_name_hint">Wallet Name</string> <string name="generate_name_hint">Wallet Name</string>
<string name="generate_password_hint">Wallet Password</string> <string name="generate_password_hint">Wallet Passphrase</string>
<string name="generate_buttonGenerate">Make me a wallet already!</string> <string name="generate_buttonGenerate">Make me a wallet already!</string>
<string name="generate_seed">Mnemonic Seed</string> <string name="generate_seed">Mnemonic Seed</string>
<string name="generate_button_accept">I have noted these 25 words!</string> <string name="generate_button_accept">I have noted these 25 words!</string>