Adding support for minimum non-letter characters.
Change-Id: I1eb96e3b88a368f1d92acdf71974fcd8fda1caab
This commit is contained in:
@@ -650,6 +650,12 @@
|
|||||||
<item quantity="other">Password must contain at least %d special symbols</item>
|
<item quantity="other">Password must contain at least %d special symbols</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
|
||||||
|
<!-- Error shown when in PASSWORD mode and password doesn't contain the required number of non-letter characters -->
|
||||||
|
<plurals name="lockpassword_password_requires_nonletter">
|
||||||
|
<item quantity="one">Password must contain at least 1 non-letter character</item>
|
||||||
|
<item quantity="other">Password must contain at least %d non-letter characters</item>
|
||||||
|
</plurals>
|
||||||
|
|
||||||
<!-- Error shown when in PASSWORD mode and password has been used recently. Please keep this string short! -->
|
<!-- Error shown when in PASSWORD mode and password has been used recently. Please keep this string short! -->
|
||||||
<string name="lockpassword_password_recently_used">Device administrator disallows using a recent password</string>
|
<string name="lockpassword_password_recently_used">Device administrator disallows using a recent password</string>
|
||||||
|
|
||||||
|
@@ -53,6 +53,7 @@ public class ChooseLockPassword extends Activity implements OnClickListener, OnE
|
|||||||
private int mPasswordMinLowerCase = 0;
|
private int mPasswordMinLowerCase = 0;
|
||||||
private int mPasswordMinSymbols = 0;
|
private int mPasswordMinSymbols = 0;
|
||||||
private int mPasswordMinNumeric = 0;
|
private int mPasswordMinNumeric = 0;
|
||||||
|
private int mPasswordMinNonLetter = 0;
|
||||||
private LockPatternUtils mLockPatternUtils;
|
private LockPatternUtils mLockPatternUtils;
|
||||||
private int mRequestedQuality = DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
|
private int mRequestedQuality = DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
|
||||||
private ChooseLockSettingsHelper mChooseLockSettingsHelper;
|
private ChooseLockSettingsHelper mChooseLockSettingsHelper;
|
||||||
@@ -71,6 +72,7 @@ public class ChooseLockPassword extends Activity implements OnClickListener, OnE
|
|||||||
public static final String PASSWORD_MIN_UPPERCASE_KEY = "lockscreen.password_min_uppercase";
|
public static final String PASSWORD_MIN_UPPERCASE_KEY = "lockscreen.password_min_uppercase";
|
||||||
public static final String PASSWORD_MIN_NUMERIC_KEY = "lockscreen.password_min_numeric";
|
public static final String PASSWORD_MIN_NUMERIC_KEY = "lockscreen.password_min_numeric";
|
||||||
public static final String PASSWORD_MIN_SYMBOLS_KEY = "lockscreen.password_min_symbols";
|
public static final String PASSWORD_MIN_SYMBOLS_KEY = "lockscreen.password_min_symbols";
|
||||||
|
public static final String PASSWORD_MIN_NONLETTER_KEY = "lockscreen.password_min_nonletter";
|
||||||
private static Handler mHandler = new Handler();
|
private static Handler mHandler = new Handler();
|
||||||
private static final int CONFIRM_EXISTING_REQUEST = 58;
|
private static final int CONFIRM_EXISTING_REQUEST = 58;
|
||||||
static final int RESULT_FINISHED = RESULT_FIRST_USER;
|
static final int RESULT_FINISHED = RESULT_FIRST_USER;
|
||||||
@@ -127,6 +129,8 @@ public class ChooseLockPassword extends Activity implements OnClickListener, OnE
|
|||||||
mPasswordMinNumeric), mLockPatternUtils.getRequestedPasswordMinimumNumeric());
|
mPasswordMinNumeric), mLockPatternUtils.getRequestedPasswordMinimumNumeric());
|
||||||
mPasswordMinSymbols = Math.max(getIntent().getIntExtra(PASSWORD_MIN_SYMBOLS_KEY,
|
mPasswordMinSymbols = Math.max(getIntent().getIntExtra(PASSWORD_MIN_SYMBOLS_KEY,
|
||||||
mPasswordMinSymbols), mLockPatternUtils.getRequestedPasswordMinimumSymbols());
|
mPasswordMinSymbols), mLockPatternUtils.getRequestedPasswordMinimumSymbols());
|
||||||
|
mPasswordMinNonLetter = Math.max(getIntent().getIntExtra(PASSWORD_MIN_NONLETTER_KEY,
|
||||||
|
mPasswordMinNonLetter), mLockPatternUtils.getRequestedPasswordMinimumNonLetter());
|
||||||
final boolean confirmCredentials = getIntent().getBooleanExtra("confirm_credentials", true);
|
final boolean confirmCredentials = getIntent().getBooleanExtra("confirm_credentials", true);
|
||||||
|
|
||||||
|
|
||||||
@@ -234,6 +238,7 @@ public class ChooseLockPassword extends Activity implements OnClickListener, OnE
|
|||||||
int lowercase = 0;
|
int lowercase = 0;
|
||||||
int symbols = 0;
|
int symbols = 0;
|
||||||
int uppercase = 0;
|
int uppercase = 0;
|
||||||
|
int nonletter = 0;
|
||||||
for (int i = 0; i < password.length(); i++) {
|
for (int i = 0; i < password.length(); i++) {
|
||||||
char c = password.charAt(i);
|
char c = password.charAt(i);
|
||||||
// allow non white space Latin-1 characters only
|
// allow non white space Latin-1 characters only
|
||||||
@@ -242,6 +247,7 @@ public class ChooseLockPassword extends Activity implements OnClickListener, OnE
|
|||||||
}
|
}
|
||||||
if (c >= '0' && c <= '9') {
|
if (c >= '0' && c <= '9') {
|
||||||
numbers++;
|
numbers++;
|
||||||
|
nonletter++;
|
||||||
} else if (c >= 'A' && c <= 'Z') {
|
} else if (c >= 'A' && c <= 'Z') {
|
||||||
letters++;
|
letters++;
|
||||||
uppercase++;
|
uppercase++;
|
||||||
@@ -250,6 +256,7 @@ public class ChooseLockPassword extends Activity implements OnClickListener, OnE
|
|||||||
lowercase++;
|
lowercase++;
|
||||||
} else {
|
} else {
|
||||||
symbols++;
|
symbols++;
|
||||||
|
nonletter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (DevicePolicyManager.PASSWORD_QUALITY_NUMERIC == mRequestedQuality
|
if (DevicePolicyManager.PASSWORD_QUALITY_NUMERIC == mRequestedQuality
|
||||||
@@ -278,6 +285,10 @@ public class ChooseLockPassword extends Activity implements OnClickListener, OnE
|
|||||||
return String.format(getResources().getQuantityString(
|
return String.format(getResources().getQuantityString(
|
||||||
R.plurals.lockpassword_password_requires_symbols, mPasswordMinSymbols),
|
R.plurals.lockpassword_password_requires_symbols, mPasswordMinSymbols),
|
||||||
mPasswordMinSymbols);
|
mPasswordMinSymbols);
|
||||||
|
} else if (nonletter < mPasswordMinNonLetter) {
|
||||||
|
return String.format(getResources().getQuantityString(
|
||||||
|
R.plurals.lockpassword_password_requires_nonletter, mPasswordMinNonLetter),
|
||||||
|
mPasswordMinNonLetter);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final boolean alphabetic = DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC
|
final boolean alphabetic = DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC
|
||||||
|
Reference in New Issue
Block a user