-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhashManager.js
57 lines (44 loc) · 1.51 KB
/
hashManager.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
52
53
54
55
56
57
require('@ostro/support/helpers')
const Manager = require('@ostro/support/manager');
class HashManager extends Manager {
$type = 'hashing';
resolve($driver) {
if (isset(this.$customCreators[$driver])) {
return this.callCustomCreator($driver);
} else {
let $method = 'create' + String.pascal($driver) + 'Driver';
if (method_exists(this, $method)) {
return this[$method]();
}
}
throw new InvalidArgumentException("Driver [" + $driver + "] not supported.");
}
callCustomCreator($driver) {
return this.$customCreators[$driver].call(this, this.$container, $driver, this.$config);
}
createBcryptDriver() {
return new(require('./bcryptHasher'))(this.getConfig('bcrypt') || {});
}
createCryptoDriver() {
return new(require('./cryptoHasher'))(this.getConfig('crypto') || {});
}
info($hashedValue) {
return this.driver().info($hashedValue);
}
make($value, $options = []) {
return this.driver().make($value, $options);
}
check($value='', $hashedValue, $options = []) {
if ($hashedValue.length === 0) {
return false;
}
return this.driver().check($value, $hashedValue, $options);
}
needsRehash($hashedValue, $options = []) {
return this.driver().needsRehash($hashedValue, $options);
}
getDefaultDriver() {
return this.getConfig('driver', 'bcrypt');
}
}
module.exports = HashManager