Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * 'settings-setup-pin-dialog' is the settings page for choosing a PIN. | 7 * 'settings-setup-pin-dialog' is the settings page for choosing a PIN. |
| 8 * | 8 * |
| 9 * Example: | 9 * Example: |
| 10 * | 10 * |
| 11 * <settings-setup-pin-dialog set-modes="[[quickUnlockSetModes]]"> | 11 * <settings-setup-pin-dialog set-modes="[[quickUnlockSetModes]]"> |
| 12 * </settings-setup-pin-dialog> | 12 * </settings-setup-pin-dialog> |
| 13 */ | 13 */ |
| 14 | 14 |
| 15 (function() { | 15 (function() { |
| 16 'use strict'; | 16 'use strict'; |
| 17 | 17 |
| 18 /** | |
| 19 * A list of the top-10 most commmonly used PINs. This list is taken from | |
| 20 * www.datagenetics.com/blog/september32012/. | |
| 21 * @const | |
| 22 */ | |
| 23 var WEAK_PINS = [ | |
| 24 '1234', '1111', '0000', '1212', '7777', '1004', '2000', '4444', '2222', | |
| 25 '6969' | |
| 26 ]; | |
| 27 | |
| 28 Polymer({ | 18 Polymer({ |
| 29 is: 'settings-setup-pin-dialog', | 19 is: 'settings-setup-pin-dialog', |
| 30 | 20 |
| 31 behaviors: [I18nBehavior], | 21 behaviors: [I18nBehavior], |
| 32 | 22 |
| 33 properties: { | 23 properties: { |
| 34 /** | 24 /** |
| 35 * The current PIN keyboard value. | 25 * The current PIN keyboard value. |
| 36 * @private | 26 * @private |
| 37 */ | 27 */ |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 this.onPinChange_(); | 89 this.onPinChange_(); |
| 100 }, | 90 }, |
| 101 | 91 |
| 102 /** @private */ | 92 /** @private */ |
| 103 onCancelTap_: function() { | 93 onCancelTap_: function() { |
| 104 this.resetState_(); | 94 this.resetState_(); |
| 105 this.$.dialog.cancel(); | 95 this.$.dialog.cancel(); |
| 106 }, | 96 }, |
| 107 | 97 |
| 108 /** | 98 /** |
| 109 * Returns true if the given PIN is likely easy to guess. | |
| 110 * @private | |
| 111 * @param {string} pin | |
| 112 * @return {boolean} | |
| 113 */ | |
| 114 isPinWeak_: function(pin) { | |
| 115 // Warn if it's a top-10 pin. | |
| 116 if (WEAK_PINS.includes(pin)) | |
| 117 return true; | |
| 118 | |
| 119 // Warn if the PIN is consecutive digits. | |
| 120 var delta = 0; | |
| 121 for (var i = 1; i < pin.length; ++i) { | |
| 122 var prev = Number(pin[i - 1]); | |
| 123 var num = Number(pin[i]); | |
| 124 if (Number.isNaN(prev) || Number.isNaN(num)) | |
| 125 return false; | |
| 126 delta = Math.max(delta, Math.abs(num - prev)); | |
| 127 } | |
| 128 | |
| 129 return delta <= 1; | |
| 130 }, | |
| 131 | |
| 132 /** | |
| 133 * Returns true if the given PIN matches PIN requirements, such as minimum | |
| 134 * length. | |
| 135 * @private | |
| 136 * @param {string|undefined} pin | |
| 137 * @return {boolean} | |
| 138 */ | |
| 139 isPinLongEnough_: function(pin) { | |
| 140 return !!pin && pin.length >= 4; | |
| 141 }, | |
| 142 | |
| 143 /** | |
| 144 * Returns true if the PIN is ready to be changed to a new value. | 99 * Returns true if the PIN is ready to be changed to a new value. |
| 145 * @private | 100 * @private |
| 146 * @return {boolean} | 101 * @return {boolean} |
| 147 */ | 102 */ |
| 148 canSubmit_: function() { | 103 canSubmit_: function() { |
| 149 return this.isPinLongEnough_(this.pinKeyboardValue_) && | 104 return this.initialPin_ == this.pinKeyboardValue_; |
| 150 this.initialPin_ == this.pinKeyboardValue_; | |
| 151 }, | 105 }, |
| 152 | 106 |
| 153 /** | 107 /** |
| 154 * Notify the user about a problem. | 108 * Notify the user about a problem. |
| 155 * @private | 109 * @private |
| 156 * @param {string} messageId | 110 * @param {string} messageId |
| 157 * @param {string} problemClass | 111 * @param {string} problemClass |
| 112 * @param {string} additionalInformation Additional information to be | |
| 113 * displayed, such as the minimum/maximum length. | |
| 158 */ | 114 */ |
| 159 showProblem_: function(messageId, problemClass) { | 115 showProblem_: function(messageId, problemClass, additionalInformation) { |
| 160 this.problemMessage_ = this.i18n(messageId); | 116 this.problemMessage_ = this.i18n(messageId, additionalInformation); |
| 161 this.problemClass_ = problemClass; | 117 this.problemClass_ = problemClass; |
| 162 this.updateStyles(); | 118 this.updateStyles(); |
| 119 this.enableSubmit_ = (problemClass != 'error'); | |
| 163 }, | 120 }, |
| 164 | 121 |
| 165 /** @private */ | 122 /** @private */ |
| 166 hideProblem_: function() { | 123 hideProblem_: function() { |
| 167 this.problemMessage_ = ''; | 124 this.problemMessage_ = ''; |
| 168 this.problemClass_ = ''; | 125 this.problemClass_ = ''; |
| 126 this.enableSubmit_ = true; | |
| 127 }, | |
| 128 | |
| 129 /** | |
| 130 * Processes the message received from the quick unlock api and hides/shows | |
| 131 * the problem based on the message. | |
| 132 * @private | |
| 133 * @param {Object} message The message received from isCredentialUsable. | |
| 134 */ | |
| 135 processPinProblems_: function(message) { | |
| 136 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.
| |
| 137 this.hideProblem_(); | |
| 138 return; | |
| 139 } | |
| 140 switch (message.failures[0]) { | |
| 141 case 'TOO_SHORT': | |
| 142 this.showProblem_('configurePinTooShort', 'error', | |
| 143 message.minLength); | |
| 144 break; | |
| 145 case 'TOO_LONG': | |
| 146 this.showProblem_('configurePinTooLong', 'error', | |
| 147 message.maxLength); | |
| 148 break; | |
| 149 case 'TOO_WEAK': | |
| 150 this.showProblem_('configurePinWeakPin', 'warning'); | |
| 151 break; | |
| 152 default: | |
| 153 assertNotReached(); | |
| 154 break; | |
| 155 } | |
| 169 }, | 156 }, |
| 170 | 157 |
| 171 /** @private */ | 158 /** @private */ |
| 172 onPinChange_: function() { | 159 onPinChange_: function() { |
| 173 if (!this.isConfirmStep_) { | 160 if (!this.isConfirmStep_) { |
| 174 var isPinLongEnough = this.isPinLongEnough_(this.pinKeyboardValue_); | 161 if (this.pinKeyboardValue_) { |
| 175 var isWeak = isPinLongEnough && this.isPinWeak_(this.pinKeyboardValue_); | 162 chrome.quickUnlockPrivate.isCredentialUsable( |
| 176 | 163 chrome.quickUnlockPrivate.QuickUnlockMode.PIN, |
| 177 if (!isPinLongEnough && this.pinKeyboardValue_) | 164 this.pinKeyboardValue_, |
| 178 this.showProblem_('configurePinTooShort', 'error'); | 165 this.processPinProblems_.bind(this)); |
| 179 else if (isWeak) | 166 } |
| 180 this.showProblem_('configurePinWeakPin', 'warning'); | |
| 181 else | |
| 182 this.hideProblem_(); | |
| 183 | |
| 184 this.enableSubmit_ = isPinLongEnough; | |
| 185 | |
| 186 } else { | 167 } else { |
| 187 var canSubmit = this.canSubmit_(); | 168 var canSubmit = this.canSubmit_(); |
| 188 | 169 |
| 189 if (!canSubmit && this.pinKeyboardValue_) | 170 if (!canSubmit && this.pinKeyboardValue_) |
| 190 this.showProblem_('configurePinMismatched', 'error'); | 171 this.showProblem_('configurePinMismatched', 'error'); |
| 191 else | 172 else |
| 192 this.hideProblem_(); | 173 this.hideProblem_(); |
| 193 | 174 |
| 194 this.enableSubmit_ = canSubmit; | 175 this.enableSubmit_ = canSubmit; |
| 195 } | 176 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 * @private | 233 * @private |
| 253 * @param {boolean} isConfirmStep | 234 * @param {boolean} isConfirmStep |
| 254 * @return {string} | 235 * @return {string} |
| 255 */ | 236 */ |
| 256 getContinueMessage_: function(isConfirmStep) { | 237 getContinueMessage_: function(isConfirmStep) { |
| 257 return this.i18n(isConfirmStep ? 'confirm' : 'configurePinContinueButton'); | 238 return this.i18n(isConfirmStep ? 'confirm' : 'configurePinContinueButton'); |
| 258 }, | 239 }, |
| 259 }); | 240 }); |
| 260 | 241 |
| 261 })(); | 242 })(); |
| OLD | NEW |