mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-20 17:11:32 -08:00
Entropy #869
This commit is contained in:
1 parent
41c0aeedbe
commit
87f69bb7e2
13 files changed
+236
-163
No files matched your search
@@ -1,5 +1,5 @@
|
||||
KeePassDX(3.4.0)
|
||||
* Show visual password strength indicator #631
|
||||
* Show visual password strength indicator with entropy #631 #869
|
||||
|
||||
KeePassDX(3.3.3)
|
||||
* Fix shared otpauth link if database not open #1274
|
||||
|
||||
+9
-60
@@ -22,33 +22,25 @@ package com.kunzisoft.keepass.activities.dialogs
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.element.Field
|
||||
import com.kunzisoft.keepass.password.PasswordGenerator
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
import com.kunzisoft.keepass.timeout.ClipboardHelper
|
||||
import com.kunzisoft.keepass.utils.PasswordEntropy
|
||||
import com.kunzisoft.keepass.view.applyFontVisibility
|
||||
import com.kunzisoft.keepass.view.PasswordView
|
||||
|
||||
class GeneratePasswordDialogFragment : DatabaseDialogFragment() {
|
||||
|
||||
private var mListener: GeneratePasswordListener? = null
|
||||
|
||||
private var root: View? = null
|
||||
private var passwordStrengthProgress: LinearProgressIndicator? = null
|
||||
private var lengthTextView: EditText? = null
|
||||
private var passwordInputLayoutView: TextInputLayout? = null
|
||||
private var passwordView: EditText? = null
|
||||
private var passwordView: PasswordView? = null
|
||||
|
||||
private var mPasswordField: Field? = null
|
||||
private var mPasswordEntropyCalculator: PasswordEntropy? = null
|
||||
|
||||
private var uppercaseBox: CompoundButton? = null
|
||||
private var lowercaseBox: CompoundButton? = null
|
||||
@@ -75,48 +67,22 @@ class GeneratePasswordDialogFragment : DatabaseDialogFragment() {
|
||||
super.onDetach()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
// To check checkboxes if a text is present
|
||||
passwordView?.addTextChangedListener(passwordTextWatcher)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
|
||||
passwordView?.removeTextChangedListener(passwordTextWatcher)
|
||||
}
|
||||
|
||||
private val passwordTextWatcher = object : TextWatcher {
|
||||
override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {}
|
||||
|
||||
override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {}
|
||||
|
||||
override fun afterTextChanged(editable: Editable) {
|
||||
getEntropyStrength(editable.toString())
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
activity?.let { activity ->
|
||||
val builder = AlertDialog.Builder(activity)
|
||||
val inflater = activity.layoutInflater
|
||||
root = inflater.inflate(R.layout.fragment_generate_password, null)
|
||||
|
||||
passwordInputLayoutView = root?.findViewById(R.id.password_input_layout)
|
||||
passwordView = root?.findViewById(R.id.password)
|
||||
passwordView?.applyFontVisibility()
|
||||
passwordView = root?.findViewById(R.id.password_view)
|
||||
val passwordCopyView: ImageView? = root?.findViewById(R.id.password_copy_button)
|
||||
passwordCopyView?.visibility = if(PreferencesUtil.allowCopyProtectedFields(activity))
|
||||
View.VISIBLE else View.GONE
|
||||
val clipboardHelper = ClipboardHelper(activity)
|
||||
passwordCopyView?.setOnClickListener {
|
||||
clipboardHelper.timeoutCopyToClipboard(passwordView!!.text.toString(),
|
||||
clipboardHelper.timeoutCopyToClipboard(passwordView!!.passwordString,
|
||||
getString(R.string.copy_field,
|
||||
getString(R.string.entry_password)))
|
||||
}
|
||||
passwordStrengthProgress = root?.findViewById(R.id.password_strength_progress)
|
||||
lengthTextView = root?.findViewById(R.id.length)
|
||||
|
||||
uppercaseBox = root?.findViewById(R.id.cb_uppercase)
|
||||
@@ -130,11 +96,6 @@ class GeneratePasswordDialogFragment : DatabaseDialogFragment() {
|
||||
extendedBox = root?.findViewById(R.id.cb_extended)
|
||||
|
||||
mPasswordField = arguments?.getParcelable(KEY_PASSWORD_FIELD)
|
||||
mPasswordEntropyCalculator = PasswordEntropy {
|
||||
passwordView?.text?.toString()?.let { firstPassword ->
|
||||
getEntropyStrength(firstPassword)
|
||||
}
|
||||
}
|
||||
|
||||
assignDefaultCharacters()
|
||||
|
||||
@@ -159,7 +120,7 @@ class GeneratePasswordDialogFragment : DatabaseDialogFragment() {
|
||||
builder.setView(root)
|
||||
.setPositiveButton(R.string.accept) { _, _ ->
|
||||
mPasswordField?.let { passwordField ->
|
||||
passwordView?.text?.toString()?.let { passwordValue ->
|
||||
passwordView?.passwordString?.let { passwordValue ->
|
||||
passwordField.protectedValue.stringValue = passwordValue
|
||||
}
|
||||
mListener?.acceptPassword(passwordField)
|
||||
@@ -181,17 +142,6 @@ class GeneratePasswordDialogFragment : DatabaseDialogFragment() {
|
||||
return super.onCreateDialog(savedInstanceState)
|
||||
}
|
||||
|
||||
private fun getEntropyStrength(passwordText: String) {
|
||||
mPasswordEntropyCalculator?.getEntropyStrength(passwordText) { entropyStrength ->
|
||||
passwordStrengthProgress?.apply {
|
||||
post {
|
||||
setIndicatorColor(entropyStrength.strength.color)
|
||||
setProgressCompat(entropyStrength.estimationPercent, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun assignDefaultCharacters() {
|
||||
uppercaseBox?.isChecked = false
|
||||
lowercaseBox?.isChecked = false
|
||||
@@ -224,8 +174,7 @@ class GeneratePasswordDialogFragment : DatabaseDialogFragment() {
|
||||
|
||||
private fun fillPassword() {
|
||||
val passwordGenerated = generatePassword()
|
||||
root?.findViewById<EditText>(R.id.password)?.setText(passwordGenerated)
|
||||
getEntropyStrength(passwordGenerated)
|
||||
passwordView?.passwordString = passwordGenerated
|
||||
}
|
||||
|
||||
private fun generatePassword(): String {
|
||||
@@ -242,11 +191,11 @@ class GeneratePasswordDialogFragment : DatabaseDialogFragment() {
|
||||
specialsBox?.isChecked == true,
|
||||
bracketsBox?.isChecked == true,
|
||||
extendedBox?.isChecked == true)
|
||||
passwordInputLayoutView?.error = null
|
||||
passwordView?.error = null
|
||||
} catch (e: NumberFormatException) {
|
||||
passwordInputLayoutView?.error = getString(R.string.error_wrong_length)
|
||||
passwordView?.error = getString(R.string.error_wrong_length)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
passwordInputLayoutView?.error = e.message
|
||||
passwordView?.error = e.message
|
||||
}
|
||||
|
||||
return password
|
||||
|
||||
+8
-25
@@ -27,12 +27,10 @@ import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.TextWatcher
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.CompoundButton
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.helpers.ExternalFileHelper
|
||||
@@ -41,6 +39,8 @@ import com.kunzisoft.keepass.model.MainCredential
|
||||
import com.kunzisoft.keepass.utils.PasswordEntropy
|
||||
import com.kunzisoft.keepass.utils.UriUtil
|
||||
import com.kunzisoft.keepass.view.KeyFileSelectionView
|
||||
import com.kunzisoft.keepass.view.PasswordView
|
||||
import com.kunzisoft.keepass.view.applyFontVisibility
|
||||
|
||||
class SetMainCredentialDialogFragment : DatabaseDialogFragment() {
|
||||
|
||||
@@ -51,9 +51,7 @@ class SetMainCredentialDialogFragment : DatabaseDialogFragment() {
|
||||
|
||||
private var passwordCheckBox: CompoundButton? = null
|
||||
|
||||
private var passwordTextInputLayout: TextInputLayout? = null
|
||||
private var passwordView: TextView? = null
|
||||
private var passwordStrengthView: LinearProgressIndicator? = null
|
||||
private var passwordView: PasswordView? = null
|
||||
private var passwordRepeatTextInputLayout: TextInputLayout? = null
|
||||
private var passwordRepeatView: TextView? = null
|
||||
|
||||
@@ -76,15 +74,6 @@ class SetMainCredentialDialogFragment : DatabaseDialogFragment() {
|
||||
|
||||
override fun afterTextChanged(editable: Editable) {
|
||||
passwordCheckBox?.isChecked = true
|
||||
// Define password strength
|
||||
mPasswordEntropyCalculator?.getEntropyStrength(editable.toString()) { entropyStrength ->
|
||||
passwordStrengthView?.apply {
|
||||
post {
|
||||
setIndicatorColor(entropyStrength.strength.color)
|
||||
setProgressCompat(entropyStrength.estimationPercent, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,16 +133,10 @@ class SetMainCredentialDialogFragment : DatabaseDialogFragment() {
|
||||
}
|
||||
|
||||
passwordCheckBox = rootView?.findViewById(R.id.password_checkbox)
|
||||
passwordTextInputLayout = rootView?.findViewById(R.id.password_input_layout)
|
||||
passwordView = rootView?.findViewById(R.id.pass_password)
|
||||
passwordStrengthView = rootView?.findViewById(R.id.password_strength_progress)
|
||||
passwordStrengthView?.apply {
|
||||
setIndicatorColor(PasswordEntropy.Strength.RISKY.color)
|
||||
progress = 0
|
||||
max = 100
|
||||
}
|
||||
passwordView = rootView?.findViewById(R.id.password_view)
|
||||
passwordRepeatTextInputLayout = rootView?.findViewById(R.id.password_repeat_input_layout)
|
||||
passwordRepeatView = rootView?.findViewById(R.id.pass_conf_password)
|
||||
passwordRepeatView = rootView?.findViewById(R.id.password_confirmation)
|
||||
passwordRepeatView?.applyFontVisibility()
|
||||
|
||||
keyFileCheckBox = rootView?.findViewById(R.id.keyfile_checkox)
|
||||
keyFileSelectionView = rootView?.findViewById(R.id.keyfile_selection)
|
||||
@@ -189,7 +172,7 @@ class SetMainCredentialDialogFragment : DatabaseDialogFragment() {
|
||||
if (allowNoMasterKey)
|
||||
showNoKeyConfirmationDialog()
|
||||
else {
|
||||
passwordTextInputLayout?.error = getString(R.string.error_disallow_no_credentials)
|
||||
passwordView?.error = getString(R.string.error_disallow_no_credentials)
|
||||
}
|
||||
}
|
||||
if (!error) {
|
||||
@@ -236,7 +219,7 @@ class SetMainCredentialDialogFragment : DatabaseDialogFragment() {
|
||||
&& passwordCheckBox!!.isChecked
|
||||
&& passwordView != null
|
||||
&& passwordRepeatView != null) {
|
||||
mMasterPassword = passwordView!!.text.toString()
|
||||
mMasterPassword = passwordView!!.passwordString
|
||||
val confPassword = passwordRepeatView!!.text.toString()
|
||||
|
||||
// Verify that passwords match
|
||||
|
||||
@@ -25,7 +25,6 @@ import me.gosimple.nbvcxz.Nbvcxz
|
||||
import me.gosimple.nbvcxz.resources.Configuration
|
||||
import me.gosimple.nbvcxz.resources.ConfigurationBuilder
|
||||
import java.util.*
|
||||
import kotlin.math.ln
|
||||
import kotlin.math.min
|
||||
|
||||
class PasswordEntropy(actionOnInitFinished: (() -> Unit)? = null) {
|
||||
@@ -54,16 +53,19 @@ class PasswordEntropy(actionOnInitFinished: (() -> Unit)? = null) {
|
||||
}
|
||||
|
||||
data class EntropyStrength(val strength: Strength,
|
||||
val entropy: Double,
|
||||
val estimationPercent: Int) {
|
||||
override fun toString(): String {
|
||||
return "EntropyStrength(strength=$strength, estimationPercent=$estimationPercent)"
|
||||
return "EntropyStrength(strength=$strength, entropy=$entropy, estimationPercent=$estimationPercent)"
|
||||
}
|
||||
}
|
||||
|
||||
fun getEntropyStrength(passwordString: String,
|
||||
entropyStrengthResult: (EntropyStrength) -> Unit) {
|
||||
val basicScore = mPasswordEntropyCalculator?.estimate(passwordString)?.basicScore ?: 0
|
||||
val percentScore = min(((ln((basicScore+2.0)) *passwordString.length)*100/60).toInt(), 100)
|
||||
val estimate = mPasswordEntropyCalculator?.estimate(passwordString)
|
||||
val basicScore = estimate?.basicScore ?: 0
|
||||
val entropy = estimate?.entropy ?: 0.0
|
||||
val percentScore = min(entropy*100/200, 100.0).toInt()
|
||||
val strength =
|
||||
if (basicScore == 0 || percentScore < 10) {
|
||||
Strength.RISKY
|
||||
@@ -71,7 +73,7 @@ class PasswordEntropy(actionOnInitFinished: (() -> Unit)? = null) {
|
||||
Strength.VERY_GUESSABLE
|
||||
} else if (basicScore == 2 || percentScore < 33) {
|
||||
Strength.SOMEWHAT_GUESSABLE
|
||||
} else if (basicScore == 3 || percentScore < 52) {
|
||||
} else if (basicScore == 3 || percentScore < 50) {
|
||||
Strength.SAFELY_UNGUESSABLE
|
||||
} else if (basicScore == 4) {
|
||||
Strength.VERY_UNGUESSABLE
|
||||
@@ -80,7 +82,7 @@ class PasswordEntropy(actionOnInitFinished: (() -> Unit)? = null) {
|
||||
}
|
||||
IOActionTask(
|
||||
{
|
||||
EntropyStrength(strength, percentScore)
|
||||
EntropyStrength(strength, entropy, percentScore)
|
||||
},
|
||||
{
|
||||
it?.let { entropyStrength -> entropyStrengthResult.invoke(entropyStrength) }
|
||||
|
||||
@@ -46,7 +46,7 @@ class MainCredentialView @JvmOverloads constructor(context: Context,
|
||||
defStyle: Int = 0)
|
||||
: FrameLayout(context, attrs, defStyle) {
|
||||
|
||||
private var passwordView: EditText
|
||||
private var passwordTextView: EditText
|
||||
private var keyFileSelectionView: KeyFileSelectionView
|
||||
private var checkboxPasswordView: CompoundButton
|
||||
private var checkboxKeyFileView: CompoundButton
|
||||
@@ -60,7 +60,7 @@ class MainCredentialView @JvmOverloads constructor(context: Context,
|
||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater?
|
||||
inflater?.inflate(R.layout.view_main_credentials, this)
|
||||
|
||||
passwordView = findViewById(R.id.password)
|
||||
passwordTextView = findViewById(R.id.password_text_view)
|
||||
keyFileSelectionView = findViewById(R.id.keyfile_selection)
|
||||
checkboxPasswordView = findViewById(R.id.password_checkbox)
|
||||
checkboxKeyFileView = findViewById(R.id.keyfile_checkox)
|
||||
@@ -75,8 +75,8 @@ class MainCredentialView @JvmOverloads constructor(context: Context,
|
||||
}
|
||||
}
|
||||
|
||||
passwordView.setOnEditorActionListener(onEditorActionListener)
|
||||
passwordView.addTextChangedListener(object : TextWatcher {
|
||||
passwordTextView.setOnEditorActionListener(onEditorActionListener)
|
||||
passwordTextView.addTextChangedListener(object : TextWatcher {
|
||||
override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {}
|
||||
|
||||
override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {}
|
||||
@@ -86,7 +86,7 @@ class MainCredentialView @JvmOverloads constructor(context: Context,
|
||||
checkboxPasswordView.isChecked = true
|
||||
}
|
||||
})
|
||||
passwordView.setOnKeyListener { _, _, keyEvent ->
|
||||
passwordTextView.setOnKeyListener { _, _, keyEvent ->
|
||||
var handled = false
|
||||
if (keyEvent.action == KeyEvent.ACTION_DOWN
|
||||
&& keyEvent?.keyCode == KeyEvent.KEYCODE_ENTER
|
||||
@@ -108,11 +108,11 @@ class MainCredentialView @JvmOverloads constructor(context: Context,
|
||||
|
||||
fun populatePasswordTextView(text: String?) {
|
||||
if (text == null || text.isEmpty()) {
|
||||
passwordView.setText("")
|
||||
passwordTextView.setText("")
|
||||
if (checkboxPasswordView.isChecked)
|
||||
checkboxPasswordView.isChecked = false
|
||||
} else {
|
||||
passwordView.setText(text)
|
||||
passwordTextView.setText(text)
|
||||
if (checkboxPasswordView.isChecked)
|
||||
checkboxPasswordView.isChecked = true
|
||||
}
|
||||
@@ -137,7 +137,7 @@ class MainCredentialView @JvmOverloads constructor(context: Context,
|
||||
fun getMainCredential(): MainCredential {
|
||||
return MainCredential().apply {
|
||||
this.masterPassword = if (checkboxPasswordView.isChecked)
|
||||
passwordView.text?.toString() else null
|
||||
passwordTextView.text?.toString() else null
|
||||
this.keyFileUri = if (checkboxKeyFileView.isChecked)
|
||||
keyFileSelectionView.uri else null
|
||||
}
|
||||
@@ -163,7 +163,7 @@ class MainCredentialView @JvmOverloads constructor(context: Context,
|
||||
*/
|
||||
fun retrieveCredentialForStorage(listener: CredentialStorageListener): ByteArray? {
|
||||
return when (mCredentialStorage) {
|
||||
CredentialStorage.PASSWORD -> listener.passwordToStore(passwordView.text?.toString())
|
||||
CredentialStorage.PASSWORD -> listener.passwordToStore(passwordTextView.text?.toString())
|
||||
CredentialStorage.KEY_FILE -> listener.keyfileToStore(keyFileSelectionView.uri)
|
||||
CredentialStorage.HARDWARE_KEY -> listener.hardwareKeyToStore()
|
||||
}
|
||||
@@ -176,15 +176,15 @@ class MainCredentialView @JvmOverloads constructor(context: Context,
|
||||
}
|
||||
|
||||
fun requestPasswordFocus() {
|
||||
passwordView.requestFocusFromTouch()
|
||||
passwordTextView.requestFocusFromTouch()
|
||||
}
|
||||
|
||||
// Auto select the password field and open keyboard
|
||||
fun focusPasswordFieldAndOpenKeyboard() {
|
||||
passwordView.postDelayed({
|
||||
passwordView.requestFocusFromTouch()
|
||||
passwordTextView.postDelayed({
|
||||
passwordTextView.requestFocusFromTouch()
|
||||
val inputMethodManager = context.getSystemService(AppCompatActivity.INPUT_METHOD_SERVICE) as? InputMethodManager?
|
||||
inputMethodManager?.showSoftInput(passwordView, InputMethodManager.SHOW_IMPLICIT)
|
||||
inputMethodManager?.showSoftInput(passwordTextView, InputMethodManager.SHOW_IMPLICIT)
|
||||
}, 100)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright 2022 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePassDX.
|
||||
*
|
||||
* KeePassDX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePassDX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.view
|
||||
|
||||
import android.content.Context
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.TextView
|
||||
import com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.utils.PasswordEntropy
|
||||
|
||||
class PasswordView @JvmOverloads constructor(context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyle: Int = 0)
|
||||
: FrameLayout(context, attrs, defStyle) {
|
||||
|
||||
private var mPasswordEntropyCalculator: PasswordEntropy? = null
|
||||
|
||||
private val passwordInputLayout: TextInputLayout
|
||||
private val passwordText: TextView
|
||||
private val passwordStrengthProgress: LinearProgressIndicator
|
||||
private val passwordEntropy: TextView
|
||||
|
||||
private var mPasswordTextWatcher: MutableList<TextWatcher> = mutableListOf()
|
||||
private val passwordTextWatcher = object : TextWatcher {
|
||||
override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {
|
||||
mPasswordTextWatcher.forEach {
|
||||
it.beforeTextChanged(charSequence, i, i1, i2)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {
|
||||
mPasswordTextWatcher.forEach {
|
||||
it.onTextChanged(charSequence, i, i1, i2)
|
||||
}
|
||||
}
|
||||
|
||||
override fun afterTextChanged(editable: Editable) {
|
||||
mPasswordTextWatcher.forEach {
|
||||
it.afterTextChanged(editable)
|
||||
}
|
||||
getEntropyStrength(editable.toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
init {
|
||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater?
|
||||
inflater?.inflate(R.layout.view_password, this)
|
||||
|
||||
passwordInputLayout = findViewById(R.id.password_input_layout)
|
||||
passwordText = findViewById(R.id.password_text)
|
||||
passwordText?.applyFontVisibility()
|
||||
passwordText.addTextChangedListener(passwordTextWatcher)
|
||||
passwordStrengthProgress = findViewById(R.id.password_strength_progress)
|
||||
passwordStrengthProgress?.apply {
|
||||
setIndicatorColor(PasswordEntropy.Strength.RISKY.color)
|
||||
progress = 0
|
||||
max = 100
|
||||
}
|
||||
passwordEntropy = findViewById(R.id.password_entropy)
|
||||
|
||||
mPasswordEntropyCalculator = PasswordEntropy {
|
||||
passwordText?.text?.toString()?.let { firstPassword ->
|
||||
getEntropyStrength(firstPassword)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getEntropyStrength(passwordText: String) {
|
||||
mPasswordEntropyCalculator?.getEntropyStrength(passwordText) { entropyStrength ->
|
||||
passwordStrengthProgress.apply {
|
||||
post {
|
||||
setIndicatorColor(entropyStrength.strength.color)
|
||||
setProgressCompat(entropyStrength.estimationPercent, true)
|
||||
}
|
||||
}
|
||||
passwordEntropy.apply {
|
||||
post {
|
||||
text = resources.getString(R.string.entropy,
|
||||
"%.${2}f".format(entropyStrength.entropy)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun addTextChangedListener(textWatcher: TextWatcher) {
|
||||
mPasswordTextWatcher.add(textWatcher)
|
||||
}
|
||||
|
||||
fun removeTextChangedListener(textWatcher: TextWatcher) {
|
||||
mPasswordTextWatcher.remove(textWatcher)
|
||||
}
|
||||
|
||||
var passwordString: String
|
||||
get() {
|
||||
return passwordText.text.toString()
|
||||
}
|
||||
set(value) {
|
||||
passwordText.text = value
|
||||
getEntropyStrength(value)
|
||||
}
|
||||
|
||||
var error: CharSequence?
|
||||
get() {
|
||||
return passwordInputLayout.error
|
||||
}
|
||||
set(value) {
|
||||
passwordInputLayout.error = value
|
||||
}
|
||||
}
|
||||
@@ -37,36 +37,13 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/password_input_layout"
|
||||
<com.kunzisoft.keepass.view.PasswordView
|
||||
android:id="@+id/password_view"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/password_copy_button"
|
||||
android:importantForAccessibility="no"
|
||||
android:importantForAutofill="no"
|
||||
app:endIconMode="password_toggle"
|
||||
app:endIconTint="?attr/colorAccent">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:hint="@string/hint_generated_password"
|
||||
android:importantForAccessibility="no"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="textPassword|textMultiLine"
|
||||
android:maxLines="3"
|
||||
tools:ignore="TextFields" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
android:id="@+id/password_strength_progress"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@+id/password_input_layout"/>
|
||||
app:layout_constraintEnd_toStartOf="@+id/password_copy_button" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageButton
|
||||
android:id="@+id/password_copy_button"
|
||||
|
||||
@@ -71,27 +71,8 @@
|
||||
android:text="@string/password"/>
|
||||
|
||||
<!-- Password Input -->
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/password_input_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:importantForAccessibility="no"
|
||||
android:importantForAutofill="no"
|
||||
app:endIconMode="password_toggle"
|
||||
app:endIconTint="?attr/colorAccent">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/pass_password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword"
|
||||
android:importantForAccessibility="no"
|
||||
android:importantForAutofill="yes"
|
||||
android:autofillHints="newPassword"
|
||||
android:maxLines="1"
|
||||
android:hint="@string/hint_pass"/>
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
<com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
android:id="@+id/password_strength_progress"
|
||||
<com.kunzisoft.keepass.view.PasswordView
|
||||
android:id="@+id/password_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
@@ -104,14 +85,14 @@
|
||||
app:endIconMode="password_toggle"
|
||||
app:endIconTint="?attr/colorAccent">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/pass_conf_password"
|
||||
android:id="@+id/password_confirmation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword"
|
||||
android:ems="10"
|
||||
android:importantForAccessibility="no"
|
||||
android:importantForAutofill="yes"
|
||||
android:autofillHints="newPassword"
|
||||
android:maxLines="1"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="textPassword|textMultiLine"
|
||||
android:maxLines="3"
|
||||
android:hint="@string/hint_conf_pass"/>
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
|
||||
@@ -36,19 +36,16 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toRightOf="@+id/password_checkbox"
|
||||
android:layout_toEndOf="@+id/password_checkbox"
|
||||
android:importantForAccessibility="no"
|
||||
android:importantForAutofill="no"
|
||||
app:endIconMode="password_toggle"
|
||||
app:endIconTint="?attr/colorAccent">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/password"
|
||||
android:id="@+id/password_text_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="48dp"
|
||||
android:hint="@string/password"
|
||||
android:inputType="textPassword"
|
||||
android:importantForAccessibility="no"
|
||||
android:importantForAutofill="yes"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/password_input_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:importantForAccessibility="no"
|
||||
android:importantForAutofill="no"
|
||||
app:endIconMode="password_toggle"
|
||||
app:endIconTint="?attr/colorAccent"
|
||||
tools:ignore="UnusedAttribute">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/password_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:hint="@string/hint_pass"
|
||||
android:importantForAccessibility="no"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="textPassword|textMultiLine"
|
||||
android:maxLines="3"
|
||||
tools:ignore="TextFields" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
android:id="@+id/password_strength_progress"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@+id/password_input_layout"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/password_entropy"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Entropy: 72.50 bit"
|
||||
android:textSize="11sp"
|
||||
android:layout_margin="4dp"
|
||||
android:textColor="?attr/colorAccent"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/password_input_layout"
|
||||
app:layout_constraintEnd_toEndOf="@+id/password_input_layout" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -603,6 +603,7 @@
|
||||
<string name="unit_kibibyte">KiB</string>
|
||||
<string name="unit_mebibyte">MiB</string>
|
||||
<string name="unit_gibibyte">GiB</string>
|
||||
<string name="entropy">Entropy: %1$s bit</string>
|
||||
<string-array name="timeout_options">
|
||||
<item>5 seconds</item>
|
||||
<item>10 seconds</item>
|
||||
|
||||
@@ -1 +1 @@
|
||||
* Show visual password strength indicator #631
|
||||
* Show visual password strength indicator with entropy #631 #869
|
||||
@@ -1 +1 @@
|
||||
* Affichage d'un indicateur visuel de la force du mot de passe #631
|
||||
* Affichage d'un indicateur visuel de la force du mot de passe avec entropie #631 #869
|
||||
Reference in new issue
Block a user