|
65 | 65 | if (true === $ICEcoder["multiUser"]) {
|
66 | 66 | // Also set value to "admin" if only 1 user (has to be admin)
|
67 | 67 | $showAdminValue = 1 === count($configUsernames) ? ' value="admin"' : '';
|
68 |
| - echo '<input type="text" name="username"' . $showAdminValue . ' class="password"><br><br>'; |
| 68 | + echo '<input type="text" name="username"' . $showAdminValue . ' class="password" id="username" onkeydown="return checkUernameKey(event.key)" onkeyup="checkUsername(this.value, true)" onchange="checkUsername(this.value, true)" onpaste="checkUsername(this.value, true)"><br><br>'; |
69 | 69 | };
|
70 | 70 | ?>
|
71 | 71 | <input type="password" name="password" class="password" id="password"<?php
|
|
128 | 128 | return document.getElementById(elem);
|
129 | 129 | };
|
130 | 130 |
|
| 131 | +// Check keydown in username field meets simple rules (alphanums, underscore and hyphen only) |
| 132 | +const checkUernameKey = function(key) { |
| 133 | + return /[\w_\-]/g.test(key); |
| 134 | +} |
| 135 | + |
| 136 | +// Check username value meets simple rules (alphanums, underscore and hyphen only) |
| 137 | +const checkUsername = function(username, amend) { |
| 138 | + // Amend username if OK to do this |
| 139 | + if (true === amend) { |
| 140 | + get("username").value = username.replace(/[^\w_\-]/g, ""); |
| 141 | + } |
| 142 | + // Return a bool based on meeting the requirements |
| 143 | + return username.replace(/[^\w_\-]/g, "").length === username.length; |
| 144 | +}; |
| 145 | + |
131 | 146 | // Check password strength and color requirements not met
|
132 | 147 | const pwStrength = function(pw) {
|
133 | 148 | // Set variables
|
|
165 | 180 |
|
166 | 181 | // Check if we can submit, else shake requirements
|
167 | 182 | const checkCanSubmit = function() {
|
168 |
| - // Password isn't strong enough, shake requirements |
| 183 | + <?php |
| 184 | + // Check username field if multiUser enabled |
| 185 | + if (true === $ICEcoder["multiUser"]) { |
| 186 | + ?>// Username isn't simple, can't submit |
| 187 | + if(false === checkUsername(get("username").value, false)) { |
| 188 | + return false; |
| 189 | + } |
| 190 | + <?php |
| 191 | + } |
| 192 | + ?>// Password isn't strong enough, shake requirements |
169 | 193 | if(false === pwStrength(get("password").value)) {
|
170 | 194 | var posArray = [24, -24, 12, -12, 6, -6, 3, -3, 0];
|
171 | 195 | var pos = -1;
|
|
0 commit comments