diff --git a/lib/user-handler.js b/lib/user-handler.js index 386d6f42..db04cc13 100644 --- a/lib/user-handler.js +++ b/lib/user-handler.js @@ -314,7 +314,7 @@ class UserHandler { }); } - setup2fa(username, callback) { + setup2fa(username, issuer, callback) { return this.database.collection('users').findOne({ username }, { @@ -340,7 +340,7 @@ class UserHandler { let otpauth_url = speakeasy.otpauthURL({ secret: base32.decode(entry.seed), label: username, - issuer: 'Wild Duck' + issuer }); return QRCode.toDataURL(otpauth_url, (err, data_url) => { if (err) { @@ -353,8 +353,7 @@ class UserHandler { let secret = speakeasy.generateSecret({ length: 20, - name: username, - issuer: 'Wild Duck' + name: username }); return this.database.collection('users').findOneAndUpdate({ @@ -374,7 +373,13 @@ class UserHandler { return callback(new Error('Could not update user, check if 2FA is not already enabled')); } - QRCode.toDataURL(secret.otpauth_url, (err, data_url) => { + let otpauth_url = speakeasy.otpauthURL({ + secret: secret.ascii, + label: username, + issuer + }); + + QRCode.toDataURL(otpauth_url, (err, data_url) => { if (err) { log.error('DB', 'QRFAIL username=%s error=%s', username, err.message); return callback(new Error('Failed to generate QR code')); diff --git a/package.json b/package.json index a06b050e..eb2928c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wildduck", - "version": "1.0.49", + "version": "1.0.50", "description": "IMAP server built with Node.js and MongoDB", "main": "server.js", "scripts": {