[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 (function () { 2 'use strict'; 3 4 /** 5 * PasswordStrength script by Thomas Kjaergaard 6 * License: MIT 7 * Repo: https://github.com/tkjaergaard/Password-Strength 8 * 9 * The MIT License (MIT) 10 * 11 * Copyright (c) 2014 Thomas Kjærgaard 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining a copy 14 * of this software and associated documentation files (the "Software"), to deal 15 * in the Software without restriction, including without limitation the rights 16 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 * copies of the Software, and to permit persons to whom the Software is 18 * furnished to do so, subject to the following conditions: 19 * 20 * The above copyright notice and this permission notice shall be included in all 21 * copies or substantial portions of the Software. 22 * 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 29 * SOFTWARE. 30 */ 31 var PasswordStrength = /*#__PURE__*/function () { 32 function PasswordStrength(settings) { 33 this.lowercase = parseInt(settings.lowercase, 10) || 0; 34 this.uppercase = parseInt(settings.uppercase, 10) || 0; 35 this.numbers = parseInt(settings.numbers, 10) || 0; 36 this.special = parseInt(settings.special, 10) || 0; 37 this.length = parseInt(settings.length, 10) || 12; 38 } 39 40 var _proto = PasswordStrength.prototype; 41 42 _proto.getScore = function getScore(value) { 43 var _this = this; 44 45 var score = 0; 46 var mods = 0; 47 var sets = ['lowercase', 'uppercase', 'numbers', 'special', 'length']; 48 sets.forEach(function (set) { 49 if (_this[set] > 0) { 50 mods += 1; 51 } 52 }); 53 score += this.constructor.calc(value, /[a-z]/g, this.lowercase, mods); 54 score += this.constructor.calc(value, /[A-Z]/g, this.uppercase, mods); 55 score += this.constructor.calc(value, /[0-9]/g, this.numbers, mods); // eslint-disable-next-line no-useless-escape 56 57 score += this.constructor.calc(value, /[$!#?=;:*\-_€%&()`´]/g, this.special, mods); 58 59 if (mods === 1) { 60 score += value.length > this.length ? 100 : 100 / this.length * value.length; 61 } else { 62 score += value.length > this.length ? 100 / mods : 100 / mods / this.length * value.length; 63 } 64 65 return score; 66 }; 67 68 PasswordStrength.calc = function calc(value, pattern, length, mods) { 69 var count = value.match(pattern); 70 71 if (count && count.length > length && length !== 0) { 72 return 100 / mods; 73 } 74 75 if (count && length > 0) { 76 return 100 / mods / length * count.length; 77 } 78 79 return 0; 80 }; 81 82 return PasswordStrength; 83 }(); 84 /** 85 * @copyright (C) 2020 Open Source Matters, Inc. <https://www.joomla.org> 86 * @license GNU General Public License version 2 or later; see LICENSE.txt 87 */ 88 89 90 (function (Joomla, document) { 91 // Method to check the input and set the meter 92 var getMeter = function getMeter(element) { 93 var meter = document.querySelector('meter'); 94 var minLength = element.getAttribute('data-min-length'); 95 var minIntegers = element.getAttribute('data-min-integers'); 96 var minSymbols = element.getAttribute('data-min-symbols'); 97 var minUppercase = element.getAttribute('data-min-uppercase'); 98 var minLowercase = element.getAttribute('data-min-lowercase'); 99 var strength = new PasswordStrength({ 100 lowercase: minLowercase || 0, 101 uppercase: minUppercase || 0, 102 numbers: minIntegers || 0, 103 special: minSymbols || 0, 104 length: minLength || 12 105 }); 106 var score = strength.getScore(element.value); 107 var i = meter.getAttribute('id').replace(/^\D+/g, ''); 108 var label = element.parentNode.parentNode.querySelector("#password-" + i); 109 110 if (score === 100) { 111 label.innerText = Joomla.Text._('JFIELD_PASSWORD_INDICATE_COMPLETE'); 112 } else { 113 label.innerText = Joomla.Text._('JFIELD_PASSWORD_INDICATE_INCOMPLETE'); 114 } 115 116 meter.value = score; 117 118 if (!element.value.length) { 119 label.innerText = ''; 120 element.setAttribute('required', ''); 121 } 122 }; 123 124 document.addEventListener('DOMContentLoaded', function () { 125 var fields = [].slice.call(document.querySelectorAll('.js-password-strength')); // Loop through the fields 126 127 fields.forEach(function (field, index) { 128 var initialVal = ''; 129 130 if (!field.value.length) { 131 initialVal = 0; 132 } // Create a progress meter and the label 133 134 135 var meter = document.createElement('meter'); 136 meter.setAttribute('id', "progress-" + index); 137 meter.setAttribute('min', 0); 138 meter.setAttribute('max', 100); 139 meter.setAttribute('low', 40); 140 meter.setAttribute('high', 99); 141 meter.setAttribute('optimum', 100); 142 meter.value = initialVal; 143 var label = document.createElement('div'); 144 label.setAttribute('class', 'text-center'); 145 label.setAttribute('id', "password-" + index); 146 label.setAttribute('aria-live', 'polite'); 147 field.parentNode.insertAdjacentElement('afterEnd', label); 148 field.parentNode.insertAdjacentElement('afterEnd', meter); // Add a data attribute for the required 149 150 if (field.value.length > 0) { 151 field.setAttribute('required', true); 152 } // Add a listener for input data change 153 154 155 field.addEventListener('keyup', function (_ref) { 156 var target = _ref.target; 157 getMeter(target); 158 }); 159 }); // Set a handler for the validation script 160 161 if (fields[0]) { 162 document.formvalidator.setHandler('password-strength', function (value) { 163 var strengthElements = document.querySelectorAll('.js-password-strength'); 164 var minLength = strengthElements[0].getAttribute('data-min-length'); 165 var minIntegers = strengthElements[0].getAttribute('data-min-integers'); 166 var minSymbols = strengthElements[0].getAttribute('data-min-symbols'); 167 var minUppercase = strengthElements[0].getAttribute('data-min-uppercase'); 168 var minLowercase = strengthElements[0].getAttribute('data-min-lowercase'); 169 var strength = new PasswordStrength({ 170 lowercase: minLowercase || 0, 171 uppercase: minUppercase || 0, 172 numbers: minIntegers || 0, 173 special: minSymbols || 0, 174 length: minLength || 12 175 }); 176 var score = strength.getScore(value); 177 178 if (score === 100) { 179 return true; 180 } 181 182 return false; 183 }); 184 } 185 }); 186 })(Joomla, document); 187 188 })();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |