added option to auto generate admin and auth record passwords from the Admin UI

This commit is contained in:
Gani Georgiev
2023-08-30 14:58:36 +03:00
parent ccb1c42220
commit e5b5c1f76f
58 changed files with 515 additions and 36525 deletions
+27 -3
View File
@@ -424,9 +424,7 @@ export default class CommonHelper {
* @param {Number} [length] Results string length (default 10)
* @return {String}
*/
static randomString(length) {
length = length || 10;
static randomString(length = 10) {
let result = "";
let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
@@ -437,6 +435,32 @@ export default class CommonHelper {
return result;
}
/**
* Generates cryptographically random secret string
* (if crypto is supported, otherwise fallback to randomString).
*
* @param {Number} [length] Results string length (default 15)
* @return {String}
*/
static randomSecret(length = 15) {
if (typeof crypto === "undefined") {
return CommonHelper.randomString(length)
}
const arr = new Uint8Array(length);
crypto.getRandomValues(arr);
const alphabet = "-_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; // 64 to devide "cleanly" 256
let result = "";
for (let i = 0; i < length; i++) {
result += alphabet.charAt(arr[i] % alphabet.length);
}
return result;
}
/**
* Converts and normalizes string into a sentence.
*