mirror of
https://github.com/plankanban/planka.git
synced 2025-12-21 09:15:51 +03:00
30
server/api/helpers/utils/generate-random-string.js
Normal file
30
server/api/helpers/utils/generate-random-string.js
Normal file
@@ -0,0 +1,30 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const crypto = require('crypto');
|
||||
|
||||
const CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
size: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
const bytes = crypto.randomBytes(inputs.size);
|
||||
|
||||
let result = '';
|
||||
for (let i = 0; i < inputs.size; i += 1) {
|
||||
result += CHARS[bytes[i] % 62];
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user