diff --git a/app/build.gradle b/app/build.gradle index 6676d8f7..1d441238 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -59,6 +59,8 @@ dependencies { compile "com.squareup.okhttp3:okhttp:$rootProject.ext.okHttpVersion" compile "com.jakewharton.timber:timber:$rootProject.ext.timberVersion" + compile 'com.nulab-inc:zxcvbn:1.2.3' + testCompile "junit:junit:$rootProject.ext.junitVersion" testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion" testCompile "com.squareup.okhttp3:mockwebserver:$rootProject.ext.okHttpVersion" diff --git a/app/src/main/java/com/m2049r/xmrwallet/GenerateFragment.java b/app/src/main/java/com/m2049r/xmrwallet/GenerateFragment.java index 1f1310cf..f5aa5664 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/GenerateFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/GenerateFragment.java @@ -21,7 +21,9 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.design.widget.TextInputLayout; import android.support.v4.app.Fragment; +import android.text.Editable; import android.text.InputType; +import android.text.TextWatcher; import android.view.KeyEvent; import android.view.LayoutInflater; 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.WalletManager; import com.m2049r.xmrwallet.util.Helper; +import com.nulabinc.zxcvbn.Strength; +import com.nulabinc.zxcvbn.Zxcvbn; import java.io.File; import java.text.ParseException; @@ -129,7 +133,7 @@ public class GenerateFragment extends Fragment { }); Helper.showKeyboard(getActivity()); -//############## + etWalletName.getEditText().setOnEditorActionListener(new TextView.OnEditorActionListener() { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 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(); + initZxcvbn(); 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() { String name = etWalletName.getEditText().getText().toString(); boolean ok = true; diff --git a/app/src/main/res/layout/layout_fabmenu.xml b/app/src/main/res/layout/layout_fabmenu.xml index 826c4d9c..35de8eec 100644 --- a/app/src/main/res/layout/layout_fabmenu.xml +++ b/app/src/main/res/layout/layout_fabmenu.xml @@ -113,7 +113,8 @@ android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_marginBottom="88dp" - android:layout_marginEnd="16dp"> + android:layout_marginEnd="16dp" + android:background="?android:attr/selectableItemBackgroundBorderless"> Archivar Copia de seguridad + Sigue escribiendo … + Mas o menos. + Puedes hacerlo mejor. + Casi … + ¡Bien ahí, hacker nivel 4! + Monederos Donar Aceptar @@ -126,7 +132,7 @@ Crear monedero Nombre del monedero - Contraseña del monedero + Frase de Contraseña ¡Házme ya un monedero! Semilla Mnemotécnica ¡He apuntado estas 25 palabras! diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fd4e8191..6bf7e758 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -15,6 +15,12 @@ Archive Backup + Continue typing … + Meh … + C\'mon, you can do better! + Getting there … + Yeah baby, h4x0r style! + Wallets Donate OK @@ -197,7 +203,7 @@ Create Wallet Wallet Name - Wallet Password + Wallet Passphrase Make me a wallet already! Mnemonic Seed I have noted these 25 words!