Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Unified Diff: chrome/browser/resources/settings/people_page/setup_pin_dialog.js

Issue 2376293005: cros: Tweaked the good/bad pin checking on the js to use the new quick unlock api function. (Closed)
Patch Set: Fixed patch set 1 errors. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/app/settings_strings.grdp ('k') | chrome/browser/ui/webui/options/browser_options_handler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/settings/people_page/setup_pin_dialog.js
diff --git a/chrome/browser/resources/settings/people_page/setup_pin_dialog.js b/chrome/browser/resources/settings/people_page/setup_pin_dialog.js
index f299a0eaea31aeff60d99f087c958cead71f0664..4ab711a57f967e577af5665a7bdb913767928ceb 100644
--- a/chrome/browser/resources/settings/people_page/setup_pin_dialog.js
+++ b/chrome/browser/resources/settings/people_page/setup_pin_dialog.js
@@ -15,16 +15,6 @@
(function() {
'use strict';
-/**
- * A list of the top-10 most commmonly used PINs. This list is taken from
- * www.datagenetics.com/blog/september32012/.
- * @const
- */
-var WEAK_PINS = [
- '1234', '1111', '0000', '1212', '7777', '1004', '2000', '4444', '2222',
- '6969'
-];
-
Polymer({
is: 'settings-setup-pin-dialog',
@@ -106,48 +96,12 @@ Polymer({
},
/**
- * Returns true if the given PIN is likely easy to guess.
- * @private
- * @param {string} pin
- * @return {boolean}
- */
- isPinWeak_: function(pin) {
- // Warn if it's a top-10 pin.
- if (WEAK_PINS.includes(pin))
- return true;
-
- // Warn if the PIN is consecutive digits.
- var delta = 0;
- for (var i = 1; i < pin.length; ++i) {
- var prev = Number(pin[i - 1]);
- var num = Number(pin[i]);
- if (Number.isNaN(prev) || Number.isNaN(num))
- return false;
- delta = Math.max(delta, Math.abs(num - prev));
- }
-
- return delta <= 1;
- },
-
- /**
- * Returns true if the given PIN matches PIN requirements, such as minimum
- * length.
- * @private
- * @param {string|undefined} pin
- * @return {boolean}
- */
- isPinLongEnough_: function(pin) {
- return !!pin && pin.length >= 4;
- },
-
- /**
* Returns true if the PIN is ready to be changed to a new value.
* @private
* @return {boolean}
*/
canSubmit_: function() {
- return this.isPinLongEnough_(this.pinKeyboardValue_) &&
- this.initialPin_ == this.pinKeyboardValue_;
+ return this.initialPin_ == this.pinKeyboardValue_;
},
/**
@@ -155,34 +109,61 @@ Polymer({
* @private
* @param {string} messageId
* @param {string} problemClass
+ * @param {string} additionalInformation Additional information to be
+ * displayed, such as the minimum/maximum length.
*/
- showProblem_: function(messageId, problemClass) {
- this.problemMessage_ = this.i18n(messageId);
+ showProblem_: function(messageId, problemClass, additionalInformation) {
+ this.problemMessage_ = this.i18n(messageId, additionalInformation);
this.problemClass_ = problemClass;
this.updateStyles();
+ this.enableSubmit_ = (problemClass != 'error');
},
/** @private */
hideProblem_: function() {
this.problemMessage_ = '';
this.problemClass_ = '';
+ this.enableSubmit_ = true;
+ },
+
+ /**
+ * Processes the message received from the quick unlock api and hides/shows
+ * the problem based on the message.
+ * @private
+ * @param {Object} message The message received from isCredentialUsable.
+ */
+ processPinProblems_: function(message) {
+ if (message.failures.length < 1) {
jdufault 2016/10/04 23:11:45 if (!messages.failures) { this.hideProblem_();
sammiequon 2016/10/24 21:16:10 Done.
+ this.hideProblem_();
+ return;
+ }
+ switch (message.failures[0]) {
+ case 'TOO_SHORT':
+ this.showProblem_('configurePinTooShort', 'error',
+ message.minLength);
+ break;
+ case 'TOO_LONG':
+ this.showProblem_('configurePinTooLong', 'error',
+ message.maxLength);
+ break;
+ case 'TOO_WEAK':
+ this.showProblem_('configurePinWeakPin', 'warning');
+ break;
+ default:
+ assertNotReached();
+ break;
+ }
},
/** @private */
onPinChange_: function() {
if (!this.isConfirmStep_) {
- var isPinLongEnough = this.isPinLongEnough_(this.pinKeyboardValue_);
- var isWeak = isPinLongEnough && this.isPinWeak_(this.pinKeyboardValue_);
-
- if (!isPinLongEnough && this.pinKeyboardValue_)
- this.showProblem_('configurePinTooShort', 'error');
- else if (isWeak)
- this.showProblem_('configurePinWeakPin', 'warning');
- else
- this.hideProblem_();
-
- this.enableSubmit_ = isPinLongEnough;
-
+ if (this.pinKeyboardValue_) {
+ chrome.quickUnlockPrivate.isCredentialUsable(
+ chrome.quickUnlockPrivate.QuickUnlockMode.PIN,
+ this.pinKeyboardValue_,
+ this.processPinProblems_.bind(this));
+ }
} else {
var canSubmit = this.canSubmit_();
« no previous file with comments | « chrome/app/settings_strings.grdp ('k') | chrome/browser/ui/webui/options/browser_options_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698