From: Tim Düsterhus Date: Mon, 17 Aug 2020 13:12:14 +0000 (+0200) Subject: Load zxcvbn on demand X-Git-Tag: 5.3.0_Alpha_1~54^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0eaf2d8c3ff26f561d1936d5a652f85b08d97919;p=GitHub%2FWoltLab%2FWCF.git Load zxcvbn on demand Resolves #3515 --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/PasswordStrength.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/PasswordStrength.js index 3207220db9..a3af899ece 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/PasswordStrength.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/PasswordStrength.js @@ -7,7 +7,7 @@ * @license GNU Lesser General Public License * @module WoltLabSuite/Core/Ui/User/PasswordStrength */ -define(['zxcvbn', 'Core', 'Language', 'StringUtil'], function (zxcvbn, Core, Language, StringUtil) { +define(['Core', 'Language'], function (Core, Language) { 'use strict'; var STATIC_DICTIONARY = []; @@ -25,17 +25,42 @@ define(['zxcvbn', 'Core', 'Language', 'StringUtil'], function (zxcvbn, Core, Lan return [].concat(value, value.split(/\W+/)); } + function initializeFeedbacker(Feedback) { + var phrases = Core.extend({}, Feedback.default_phrases); + for (var type in phrases) { + if (phrases.hasOwnProperty(type)) { + for (var phrase in phrases[type]) { + if (phrases[type].hasOwnProperty(phrase)) { + var languageItem = 'wcf.user.password.zxcvbn.' + type + '.' + phrase; + var value = Language.get(languageItem); + if (value !== languageItem) { + phrases[type][phrase] = value; + } + } + } + } + } + return new Feedback(phrases); + } + /** * @constructor */ - function PasswordStrength(input, options) { this.init(input, options); } + function PasswordStrength(input, options) { + require(['zxcvbn']).then(function (modules) { + var zxcvbn = modules[0]; + this.init(zxcvbn, input, options); + }.bind(this)); + } PasswordStrength.prototype = { /** - * @param {Element} input + * @param {*} zxcvbn + * @param {Element} input * @param {object} options */ - init: function (input, options) { + init: function (zxcvbn, input, options) { + this._zxcvbn = zxcvbn; this._input = input; this._options = Core.extend({ @@ -44,21 +69,7 @@ define(['zxcvbn', 'Core', 'Language', 'StringUtil'], function (zxcvbn, Core, Lan }, options); if (!this._options.feedbacker) { - var phrases = Core.extend({}, zxcvbn.Feedback.default_phrases); - for (var type in phrases) { - if (phrases.hasOwnProperty(type)) { - for (var phrase in phrases[type]) { - if (phrases[type].hasOwnProperty(phrase)) { - var languageItem = 'wcf.user.password.zxcvbn.' + type + '.' + phrase; - var value = Language.get(languageItem); - if (value !== languageItem) { - phrases[type][phrase] = value; - } - } - } - } - } - this._options.feedbacker = new zxcvbn.Feedback(phrases); + this._options.feedbacker = initializeFeedbacker(zxcvbn.Feedback); } this._wrapper = elCreate('div'); @@ -119,7 +130,7 @@ define(['zxcvbn', 'Core', 'Language', 'StringUtil'], function (zxcvbn, Core, Lan // To bound runtime latency for really long passwords, consider sending zxcvbn() only // the first 100 characters or so of user input. - var verdict = zxcvbn(value.substr(0, 100), dictionary); + var verdict = this._zxcvbn(value.substr(0, 100), dictionary); verdict.feedback = this._options.feedbacker.from_result(verdict); elData(this._score, 'score', value.length === 0 ? '-1' : verdict.score);