-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
45 lines (41 loc) · 964 Bytes
/
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
var bcrypt = require('bcrypt');
var uuid = require('node-uuid');
module.exports.createHash = function (str, cost, cb) {
bcrypt.genSalt(cost || 10, function (error, salt) {
if (error) {
return cb(error);
}
bcrypt.hash(str, salt, function (error, hash) {
if (error) {
return cb(error);
}
cb(null, hash);
});
});
};
module.exports.validateHash = function (str, hash, cb) {
bcrypt.compare(str, hash, function (error, res) {
if (error) {
return cb(error);
}
cb(null, res);
});
};
module.exports.createSalt = function (cost, cb) {
bcrypt.genSalt(cost || 10, function (error, salt) {
if (error) {
return cb(error);
}
cb(error, salt);
});
};
module.exports.uuid = function (version, options, buffer, offset) {
switch (version) {
case 1:
return uuid.v1(options || null, buffer || null, offset || null);
case 4:
return uuid.v4(options || null, buffer || null, offset || null);
default:
return null;
}
};