mirror of
https://github.com/plankanban/planka.git
synced 2025-12-21 09:15:51 +03:00
19
server/api/helpers/utils/generate-api-key.js
Normal file
19
server/api/helpers/utils/generate-api-key.js
Normal file
@@ -0,0 +1,19 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
fn() {
|
||||
const prefix = sails.helpers.utils.generateRandomString(8);
|
||||
const secret = sails.helpers.utils.generateRandomString(32);
|
||||
const key = `${prefix}_${secret}`;
|
||||
|
||||
return {
|
||||
key,
|
||||
prefix,
|
||||
};
|
||||
},
|
||||
};
|
||||
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;
|
||||
},
|
||||
};
|
||||
21
server/api/helpers/utils/hash.js
Normal file
21
server/api/helpers/utils/hash.js
Normal file
@@ -0,0 +1,21 @@
|
||||
/*!
|
||||
* 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');
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
data: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
return crypto.createHash('sha256').update(inputs.data).digest('hex');
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user