diff --git a/lib/user-handler.js b/lib/user-handler.js index 27be1764..0222bc18 100644 --- a/lib/user-handler.js +++ b/lib/user-handler.js @@ -314,6 +314,37 @@ class UserHandler { }); } + reset(username, callback) { + let password = generatePassword.generate({ + length: 12, + uppercase: true, + numbers: true, + symbols: false + }); + + return this.database.collection('users').findOneAndUpdate({ + username + }, { + $set: { + enabled2fa: false, + seed: '', + requirePasswordChange: true, + password: bcrypt.hashSync(password, 11) + } + }, {}, (err, result) => { + if (err) { + log.error('DB', 'UPDATEFAIL username=%s error=%s', username, err.message); + return callback(new Error('Database Error, failed to reset user credentials')); + } + + if (!result || !result.value) { + return callback(new Error('Could not update user')); + } + + return callback(null, password); + }); + } + setup2fa(username, issuer, callback) { return this.database.collection('users').findOne({ username diff --git a/package-lock.json b/package-lock.json index 15ac1662..640a1d92 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "wildduck", - "version": "1.0.50", + "version": "1.0.51", "lockfileVersion": 1, "dependencies": { "@ronomon/crypto-async": { diff --git a/package.json b/package.json index 8361d4be..3d7cbf92 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wildduck", - "version": "1.0.51", + "version": "1.0.52", "description": "IMAP server built with Node.js and MongoDB", "main": "server.js", "scripts": {