-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
51 lines (47 loc) · 1.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const bcrypt = require('bcryptjs')
const POST_ACTION_BASE64 = 'base64'
module.exports.templateTags = [
{
name: 'bcrypt',
displayName: 'BCrypt',
description: 'Encrypts a password using bcrypt',
args: [
{
displayName: 'Rounds',
description: 'See bcrypt documentation',
type: 'number',
defaultValue: 10,
},
{
displayName: 'Post-Action',
description: 'Action after encryption',
type: 'enum',
defaultValue: 'none',
options: [
{
displayName: 'none',
value: 'none',
description: 'No further action',
},
{
displayName: 'Base64 -> Encode',
value: POST_ACTION_BASE64,
description: 'Encode the string after encryption',
},
],
},
{
displayName: 'Password',
type: 'string',
},
],
async run(context, rounds, post_action, password) {
const hash = await bcrypt.hash(password, rounds)
switch (post_action) {
case POST_ACTION_BASE64:
return btoa(hash)
}
return hash
}
}
]