mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
PASSWORD_MIN_LENGTH (default 8) is now the length below which a sign-in is REPORTED, in the new Admin Panel / Problems / Password length, and PASSWORD_MIN_LENGTH_ENFORCE (off by default) is what makes it a rule: a shorter new password is refused, and an account that signs in with an older shorter one sees only "Change your password" until it has a long enough one. Signing in is never refused, enforced or not, so nobody is locked out by a minimum set after their password. LDAP, OAuth2, OIDC, SAML, CAS and Sandstorm accounts are neither reported nor asked: their password is their provider's. An administrator's Set password no longer applies WeKan's policy to such an account. Meteor sends a password hashed, so only the browser knows its length: it notes it on the sign-in form and, after a sign-in that worked, says "it was short" - never the password or its length. The page has both settings and a table, one row per account: username, first and last short-password login, the latest IPv4 and IPv6 address with the country's flag and city when a CDN says where it is, the count, and when it was fixed, with the Too short (default) / Fixed / All filter. Fixed is a changed password not seen short since; a short one seen again reopens the row. Changing one's own password - Member Settings, the forced change, a reset link - now signs EVERY session of the account out, the one that changed it too, and only the new password signs in again. The browser goes to the sign-in page as soon as it is signed out, since the server closes the connection before the answer can arrive. Documented in docs/Features/Admin-Panel/Problems/Password-length.md, the settings on every platform. The new strings are in every locale in English for now. Tests: passwordPolicy, passwordChangeRequired and shortPasswordLogins (node); password-min-length-signup-login, password-length-report and password-change-other-sessions (Playwright, Chromium and WebKit), which change each setting on the page and check what it does, and that sign-up with no mail server registers and signs the user in. Thanks to xet7 !
78 lines
2.7 KiB
JavaScript
78 lines
2.7 KiB
JavaScript
import { Blaze } from 'meteor/blaze';
|
|
import { Template } from 'meteor/templating';
|
|
import { Tracker } from 'meteor/tracker';
|
|
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
|
|
|
|
// PASSWORD_MIN_LENGTH: after signing in, ask whether this account must change
|
|
// a password shorter than the minimum, and if so show nothing but the Change
|
|
// Password form (passwordChangeRequired.jade). The server asks the question
|
|
// (server/passwordChangeRequired.js); config/accounts.js tells it when the
|
|
// password just typed was too short. Changing a password signs every session
|
|
// out, so the account then signs in again, with the new password.
|
|
let overlay = null;
|
|
|
|
function closeOverlay() {
|
|
if (!overlay) return;
|
|
Blaze.remove(overlay.view);
|
|
overlay.node.remove();
|
|
overlay = null;
|
|
}
|
|
|
|
function openOverlay(min) {
|
|
if (overlay) return;
|
|
const node = document.createElement('div');
|
|
document.body.appendChild(node);
|
|
overlay = { node, view: Blaze.renderWithData(Template.passwordChangeRequired, { min }, node) };
|
|
}
|
|
|
|
Template.passwordChangeRequired.events({
|
|
'click .js-password-change-required-logout'() {
|
|
Meteor.logout(() => closeOverlay());
|
|
},
|
|
});
|
|
|
|
export function checkPasswordChangeRequirement() {
|
|
const userId = Meteor.userId();
|
|
if (!userId) return;
|
|
Meteor.call('getPasswordChangeRequirement', (error, result) => {
|
|
if (error || !result || Meteor.userId() !== userId) return;
|
|
if (result.required) openOverlay(result.minLength);
|
|
});
|
|
}
|
|
|
|
// A changed password signs this session out too (server/passwordChangeRequired.js).
|
|
// The server closes the connection as it removes the token, so the answer to
|
|
// the change - and useraccounts' onSubmitHook - may never arrive; being signed
|
|
// out soon after submitting a change is the answer, and the next stop is the
|
|
// sign-in page, from Member Settings and from this overlay alike.
|
|
const SIGN_OUT_WAIT_MS = 2 * 60 * 1000;
|
|
let changeSubmittedAt = 0;
|
|
document.addEventListener('submit', event => {
|
|
const form = event.target;
|
|
if (form && form.id === 'at-pwd-form' && form.querySelector('#at-field-current_password')) {
|
|
changeSubmittedAt = Date.now();
|
|
}
|
|
}, true);
|
|
|
|
Meteor.startup(() => {
|
|
let askedFor = null;
|
|
Tracker.autorun(() => {
|
|
const userId = Meteor.userId();
|
|
if (!userId) {
|
|
askedFor = null;
|
|
const changed = Date.now() - changeSubmittedAt < SIGN_OUT_WAIT_MS;
|
|
if (overlay || changed) {
|
|
// The change signed every session out: sign in with the new password.
|
|
changeSubmittedAt = 0;
|
|
closeOverlay();
|
|
Popup.close?.();
|
|
FlowRouter.go('atSignIn');
|
|
}
|
|
return;
|
|
}
|
|
if (askedFor === userId) return;
|
|
askedFor = userId;
|
|
Tracker.nonreactive(checkPasswordChangeRequirement);
|
|
});
|
|
});
|