|
| 1 | +let debounceTimeout; |
| 2 | +let storedLogin = ""; |
| 3 | +let storedName = ""; |
| 4 | +let storedSurname = ""; |
| 5 | +const getNameApiUrl = "/rest/v1/getnamesurnamefromlogin.php"; |
| 6 | + |
| 7 | +const updateNameSurname = async () => { |
| 8 | + const response = await fetch(getNameApiUrl, { |
| 9 | + method: "POST", |
| 10 | + headers: {'Content-Type': 'application/x-www-form-urlencoded'}, |
| 11 | + body: new URLSearchParams({'login': storedLogin}).toString(), |
| 12 | + }); |
| 13 | + const rawResponse = await response.text(); |
| 14 | + const parsedResponse = JSON.parse(rawResponse); |
| 15 | + |
| 16 | + if (response.ok) { |
| 17 | + storedName = parsedResponse['name'].toUpperCase(); |
| 18 | + storedSurname = parsedResponse['surname'].toUpperCase(); |
| 19 | + } |
| 20 | + else if (response.status === 404) { |
| 21 | + storedName = ""; |
| 22 | + storedSurname = ""; |
| 23 | + } |
| 24 | + else if (response.status === 400) { |
| 25 | + console.log("Error while trying to query " + getNameApiUrl + " api endpoint : invalid request"); |
| 26 | + console.log(parsedResponse['message']); |
| 27 | + } |
| 28 | + else { |
| 29 | + console.log("Error while trying to query " + getNameApiUrl + " api endpoint : server error"); |
| 30 | + console.log(parsedResponse['message']); |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +const doesPwdContainNameSurname = (password) => { |
| 35 | + const upperPwd = password.toUpperCase(); |
| 36 | + return ( |
| 37 | + (storedName !== "" && upperPwd.includes(storedName)) || |
| 38 | + (storedSurname !== "" && upperPwd.includes(storedSurname)) |
| 39 | + ); |
| 40 | +} |
| 41 | + |
1 | 42 | (function() {
|
2 | 43 | var barWidth, bootstrapClasses, displayEntropyBar, displayEntropyBarMsg, ppolicyResults;
|
3 | 44 |
|
|
79 | 120 | // returns 2: 0
|
80 | 121 |
|
81 | 122 | if (first === null ||
|
82 |
| - second === null || |
83 |
| - typeof first === 'undefined' || |
84 |
| - typeof second === 'undefined') { |
| 123 | + second === null || |
| 124 | + typeof first === 'undefined' || |
| 125 | + typeof second === 'undefined') { |
85 | 126 | return 0
|
86 | 127 | }
|
87 | 128 |
|
|
120 | 161 |
|
121 | 162 | if ((pos1 + max < firstLength) && (pos2 + max < secondLength)) {
|
122 | 163 | sum += similar_text(
|
123 |
| - first.substr(pos1 + max, firstLength - pos1 - max), |
124 |
| - second.substr(pos2 + max, |
125 |
| - secondLength - pos2 - max)) |
| 164 | + first.substr(pos1 + max, firstLength - pos1 - max), |
| 165 | + second.substr(pos2 + max, |
| 166 | + secondLength - pos2 - max)) |
126 | 167 | }
|
127 | 168 | }
|
128 | 169 |
|
|
215 | 256 | }
|
216 | 257 | }
|
217 | 258 |
|
| 259 | + if (local_policy.pwd_diff_namesurname && local_policy.use_restapi) { |
| 260 | + setResult('ppolicy-pwd_diff_namesurname-feedback', "waiting"); |
| 261 | + if(login !== storedLogin) { |
| 262 | + storedLogin = login; |
| 263 | + clearTimeout(debounceTimeout); |
| 264 | + debounceTimeout = setTimeout(async () => { |
| 265 | + await updateNameSurname(); |
| 266 | + report( !doesPwdContainNameSurname(password), "ppolicy-pwd_diff_namesurname-feedback" ); |
| 267 | + }, 1000); |
| 268 | + } |
| 269 | + else { |
| 270 | + report( !doesPwdContainNameSurname(password), "ppolicy-pwd_diff_namesurname-feedback" ); |
| 271 | + } |
| 272 | + } |
| 273 | + |
218 | 274 | if (local_policy.pwd_diff_last_min_chars > 0) {
|
219 | 275 | if( $( "#oldpassword" ).length )
|
220 | 276 | {
|
|
259 | 315 | }
|
260 | 316 |
|
261 | 317 | if ( local_policy.pwd_no_special_at_ends &&
|
262 |
| - local_policy.pwd_no_special_at_ends == true && |
263 |
| - local_policy.pwd_special_chars ) { |
| 318 | + local_policy.pwd_no_special_at_ends == true && |
| 319 | + local_policy.pwd_special_chars ) { |
264 | 320 | var re_start = new RegExp("^["+local_policy.pwd_special_chars+"]","");
|
265 | 321 | var re_end = new RegExp("["+local_policy.pwd_special_chars+"]$","");
|
266 | 322 | report( ( !password.match(re_start) && !password.match(re_end) ) , 'ppolicy-pwd_no_special_at_ends-feedback');
|
|
0 commit comments