Skip to content

EspoCRM – Open Source CRM Application

secure frontend password generation

Yuri Kuznetsovba15bf8d7e79
diff --git a/client/src/views/user/fields/generate-password.js b/client/src/views/user/fields/generate-password.js
index 1032503c6d..02221f7990 100644
--- a/client/src/views/user/fields/generate-password.js
+++ b/client/src/views/user/fields/generate-password.js
@@ -166,14 +166,20 @@ class UserGeneratePasswordFieldView extends BaseFieldView {
const setList = [letters, numbers, either, upperCase, lowerCase, specialCharacters];
const shuffle = function (array) {
- let currentIndex = array.length, temporaryValue, randomIndex;
+ let currentIndex = array.length;
while (0 !== currentIndex) {
- randomIndex = Math.floor(Math.random() * currentIndex);
+ const randomArray = new Uint32Array(1);
+ crypto.getRandomValues(randomArray);
+
+ const randomIndex = Math.floor((randomArray[0] / (0xFFFFFFFF + 1)) * currentIndex);
+
currentIndex -= 1;
- temporaryValue = array[currentIndex];
+
+ const tempValue = array[currentIndex];
+
array[currentIndex] = array[randomIndex];
- array[randomIndex] = temporaryValue;
+ array[randomIndex] = tempValue;
}
return array;