Add a password strength estimator wrapping the SDK zxcvbn API (#7186)

* Add a password strength estimator wrapping the SDK zxcvbn API

* Add tests for the password strength estimator SDK mapping

---------

Co-authored-by: ElementBot <android@element.io>
This commit is contained in:
Jenna Vassar
2026-07-28 03:30:06 -07:00
committed by GitHub
parent 0cd163a680
commit fe24aeb2ce
4 changed files with 184 additions and 0 deletions
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2026 Element Creations Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.libraries.matrix.test.encryption
import io.element.android.libraries.matrix.api.encryption.PasswordStrengthEstimate
import io.element.android.libraries.matrix.api.encryption.PasswordStrengthEstimator
import io.element.android.libraries.matrix.api.encryption.PasswordStrengthRanking
class FakePasswordStrengthEstimator(
private val estimateResult: (password: String, userInputs: List<String>) -> PasswordStrengthEstimate =
{ _, _ -> aPasswordStrengthEstimate() },
) : PasswordStrengthEstimator {
override fun estimate(password: String, userInputs: List<String>): PasswordStrengthEstimate =
estimateResult(password, userInputs)
}
fun aPasswordStrengthEstimate(
ranking: PasswordStrengthRanking = PasswordStrengthRanking.Strong,
score: Double = 18.0,
normalScore: Double = 0.7,
) = PasswordStrengthEstimate(
ranking = ranking,
score = score,
normalScore = normalScore,
)