ChooseLockPassword: convert to use PasswordMetrics#validateCredential()

Fix the check for invalid characters in new passwords by switching from
PasswordMetrics#validatePassword() to
PasswordMetrics#validateCredential().  For more information, see
frameworks/base change I5c3c55367c3a294578cd0f97ac0e315a11ed517e.

Bug: 219511761
Bug: 232900169
Bug: 243881358
Test: Verified no regressions in 'atest ChooseLockPasswordTest'.  Note,
      this test is currently @Ignored and has 2 failures.  I didn't
      attempt to address that.
Test: Set a password containing non-ASCII characters on a device running
      an older build.  Upgraded and verified unlocking still works.
      Tested that setting a new non-ASCII password is not allowed.
Change-Id: I5f1822a34688473cb103eb64dca56e4c19d4dd08
This commit is contained in:
Eric Biggers
2023-06-21 02:56:41 +00:00
parent 7f45861797
commit b547094366
2 changed files with 33 additions and 16 deletions

View File

@@ -705,18 +705,17 @@ public class ChooseLockPassword extends SettingsActivity {
/**
* Validates PIN/Password and returns the validation result and updates mValidationErrors
* and mPasswordReused to reflect validation results.
* to reflect validation results.
*
* @param credential credential the user typed in.
* @return whether password satisfies all the requirements.
*/
@VisibleForTesting
boolean validatePassword(LockscreenCredential credential) {
final byte[] password = credential.getCredential();
mValidationErrors = PasswordMetrics.validatePassword(
mMinMetrics, mMinComplexity, !mIsAlphaMode, password);
if (mValidationErrors.isEmpty() && mLockPatternUtils.checkPasswordHistory(
password, getPasswordHistoryHashFactor(), mUserId)) {
mValidationErrors = PasswordMetrics.validateCredential(mMinMetrics, mMinComplexity,
credential);
if (mValidationErrors.isEmpty() && mLockPatternUtils.checkPasswordHistory(
credential.getCredential(), getPasswordHistoryHashFactor(), mUserId)) {
mValidationErrors =
Collections.singletonList(new PasswordValidationError(RECENTLY_USED));
}
@@ -893,8 +892,8 @@ public class ChooseLockPassword extends SettingsActivity {
final boolean canInput = mSaveAndFinishWorker == null;
LockscreenCredential password = mIsAlphaMode
? LockscreenCredential.createPasswordOrNone(mPasswordEntry.getText())
: LockscreenCredential.createPinOrNone(mPasswordEntry.getText());
? LockscreenCredential.createPassword(mPasswordEntry.getText())
: LockscreenCredential.createPin(mPasswordEntry.getText());
final int length = password.size();
if (mUiStage == Stage.Introduction) {
mPasswordRestrictionView.setVisibility(View.VISIBLE);