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_ = loadTimeData.getStringF(messageId, |
jdufault
2016/09/30 16:40:45
It looks like this.i18n handles parameters as well
sammiequon
2016/09/30 18:50:26
Done.
| |
117 additionalInformation); | |
161 this.problemClass_ = problemClass; | 118 this.problemClass_ = problemClass; |
162 this.updateStyles(); | 119 this.updateStyles(); |
120 this.enableSubmit_ = (problemClass != 'error'); | |
163 }, | 121 }, |
164 | 122 |
165 /** @private */ | 123 /** @private */ |
166 hideProblem_: function() { | 124 hideProblem_: function() { |
167 this.problemMessage_ = ''; | 125 this.problemMessage_ = ''; |
168 this.problemClass_ = ''; | 126 this.problemClass_ = ''; |
127 this.enableSubmit_ = true; | |
128 }, | |
129 | |
130 /** | |
131 * Processes the message received from the quick unlock api and hides/shows | |
132 * the problem based on the message. | |
133 * @private | |
134 * @param {Object} message The message received from isCredentialUsable. | |
135 */ | |
136 processCredentials_: function(message) { | |
jdufault
2016/09/30 16:40:45
What about naming this processPinProblems_?
sammiequon
2016/09/30 18:50:26
Done.
| |
137 if (message.failures.length < 1) { | |
138 this.hideProblem_(); | |
139 return; | |
140 } | |
141 switch (message.failures[0]) { | |
142 case 'TOO_SHORT': | |
143 this.showProblem_('configurePinTooShort', 'error', | |
144 message.minLength); | |
145 break; | |
146 case 'TOO_LONG': | |
147 this.showProblem_('configurePinTooLong', 'error', | |
148 message.maxLength); | |
149 break; | |
150 case 'TOO_WEAK': | |
151 this.showProblem_('configurePinWeakPin', 'warning'); | |
152 break; | |
153 default: | |
154 assertNotReached(); | |
155 break; | |
156 } | |
169 }, | 157 }, |
170 | 158 |
171 /** @private */ | 159 /** @private */ |
172 onPinChange_: function() { | 160 onPinChange_: function() { |
173 if (!this.isConfirmStep_) { | 161 if (!this.isConfirmStep_) { |
174 var isPinLongEnough = this.isPinLongEnough_(this.pinKeyboardValue_); | 162 if (this.pinKeyboardValue_) { |
175 var isWeak = isPinLongEnough && this.isPinWeak_(this.pinKeyboardValue_); | 163 chrome.quickUnlockPrivate.isCredentialUsable( |
176 | 164 chrome.quickUnlockPrivate.QuickUnlockMode.PIN, |
177 if (!isPinLongEnough && this.pinKeyboardValue_) | 165 this.pinKeyboardValue_, |
178 this.showProblem_('configurePinTooShort', 'error'); | 166 this.processCredentials_.bind(this)); |
179 else if (isWeak) | 167 } |
180 this.showProblem_('configurePinWeakPin', 'warning'); | |
181 else | |
182 this.hideProblem_(); | |
183 | |
184 this.enableSubmit_ = isPinLongEnough; | |
185 | |
186 } else { | 168 } else { |
187 var canSubmit = this.canSubmit_(); | 169 var canSubmit = this.canSubmit_(); |
188 | 170 |
189 if (!canSubmit && this.pinKeyboardValue_) | 171 if (!canSubmit && this.pinKeyboardValue_) |
190 this.showProblem_('configurePinMismatched', 'error'); | 172 this.showProblem_('configurePinMismatched', 'error'); |
191 else | 173 else |
192 this.hideProblem_(); | 174 this.hideProblem_(); |
193 | 175 |
194 this.enableSubmit_ = canSubmit; | 176 this.enableSubmit_ = canSubmit; |
195 } | 177 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 * @private | 234 * @private |
253 * @param {boolean} isConfirmStep | 235 * @param {boolean} isConfirmStep |
254 * @return {string} | 236 * @return {string} |
255 */ | 237 */ |
256 getContinueMessage_: function(isConfirmStep) { | 238 getContinueMessage_: function(isConfirmStep) { |
257 return this.i18n(isConfirmStep ? 'confirm' : 'configurePinContinueButton'); | 239 return this.i18n(isConfirmStep ? 'confirm' : 'configurePinContinueButton'); |
258 }, | 240 }, |
259 }); | 241 }); |
260 | 242 |
261 })(); | 243 })(); |
OLD | NEW |