forked from travis4all/autheremin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autheremin.js
36 lines (31 loc) · 892 Bytes
/
autheremin.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
var bcrypt = require('bcrypt')
module.exports = function(db) {
var autheremin = {}
autheremin.create = function(username, password, cb) {
bcrypt.hash(password, 8, function(err, hash) {
if (err) return cb(err)
db.set('autheremin:'+username, hash, function(err) {
if (err) return cb(err)
cb()
})
})
}
autheremin.delete = function(username, cb) {
db.del('autheremin:'+username, function(err) {
if (err) return cb(err)
cb()
})
}
autheremin.verify = function(username, password, cb) {
db.get('autheremin:'+username, function(err, hash) {
if (err) return cb(err)
if (!hash) return cb(new Error('No match'))
bcrypt.compare(password, hash, function(err, res) {
if (err) return cb(err)
if (!res) return cb(new Error('No match'))
cb()
})
})
}
return autheremin
}