diff --git a/application/helper.js b/application/helper.js index c925a65..2b5557f 100644 --- a/application/helper.js +++ b/application/helper.js @@ -84,6 +84,20 @@ class Helper { return footer } + + /** + * Shuffle an array using the Durstenfeld shuffle algorithm + * @param {Array} array + * @returns {Array} + */ + + shuffleArray(array) { + for (let i = array.length - 1; i >= 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]]; + } + return array + } } module.exports = Helper diff --git a/infrastructure/web/routes/login.js b/infrastructure/web/routes/login.js index acc7776..1ceaf93 100644 --- a/infrastructure/web/routes/login.js +++ b/infrastructure/web/routes/login.js @@ -14,7 +14,7 @@ router.get('/', (req, res, _next) => { title: `${config.http.branding[0]} | Your temporary Inbox`, username: randomWord(), purgeTime: purgeTime, - domains: config.email.domains, + domains: helper.shuffleArray(config.email.domains), branding: config.http.branding, }) })