Skip to content

Node.js based forum software built for the modern web

feat: password check hook (#11853)

Opliko8ac34f8e8e63
diff --git a/src/controllers/authentication.js b/src/controllers/authentication.js
index 58eff94299..08515f1124 100644
--- a/src/controllers/authentication.js
+++ b/src/controllers/authentication.js
@@ -102,6 +102,8 @@ authenticationController.register = async function (req, res) {
user.isPasswordValid(userData.password);
+ await plugins.hooks.fire('filter:password.check', { password: userData.password, uid: 0, userData: userData });
+
res.locals.processLogin = true; // set it to false in plugin if you wish to just register only
await plugins.hooks.fire('filter:register.check', { req: req, res: res, userData: userData });
diff --git a/src/user/profile.js b/src/user/profile.js
index 09c4814410..8daba09758 100644
--- a/src/user/profile.js
+++ b/src/user/profile.js
@@ -310,6 +310,8 @@ module.exports = function (User) {
throw new Error('[[user:change_password_error_privileges]]');
}
+ await plugins.hooks.fire('filter:password.check', { password: data.newPassword, uid: data.uid });
+
if (isSelf && hasPassword) {
const correct = await User.isPasswordCorrect(data.uid, data.currentPassword, data.ip);
if (!correct) {
diff --git a/src/user/reset.js b/src/user/reset.js
index 557a83285c..9a6d6330ff 100644
--- a/src/user/reset.js
+++ b/src/user/reset.js
@@ -12,6 +12,7 @@ const db = require('../database');
const meta = require('../meta');
const emailer = require('../emailer');
const Password = require('../password');
+const plugins = require('../plugins');
const UserReset = module.exports;
@@ -92,8 +93,11 @@ UserReset.commit = async function (code, password) {
}
const userData = await db.getObjectFields(
`user:${uid}`,
- ['password', 'passwordExpiry', 'password:shaWrapped']
+ ['password', 'passwordExpiry', 'password:shaWrapped', 'username']
);
+
+ await plugins.hooks.fire('filter:password.check', { password: password, uid });
+
const ok = await Password.compare(password, userData.password, !!parseInt(userData['password:shaWrapped'], 10));
if (ok) {
throw new Error('[[error:reset-same-password]]');