mirror of
https://github.com/status-im/codimd.git
synced 2025-01-28 23:25:18 +00:00
add methods for password hashing in User model
Signed-off-by: BinotaLIU <me@binota.org>
This commit is contained in:
parent
527c3ae7d9
commit
ec206db173
@ -1,7 +1,7 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
// external modules
|
// external modules
|
||||||
var Sequelize = require('sequelize')
|
var Sequelize = require('sequelize')
|
||||||
var scrypt = require('scrypt')
|
var Scrypt = require('scrypt-kdf')
|
||||||
|
|
||||||
// core
|
// core
|
||||||
var logger = require('../logger')
|
var logger = require('../logger')
|
||||||
@ -41,20 +41,20 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
password: {
|
password: {
|
||||||
type: Sequelize.TEXT,
|
type: Sequelize.TEXT
|
||||||
set: function (value) {
|
|
||||||
var hash = scrypt.kdfSync(value, scrypt.paramsSync(0.1)).toString('hex')
|
|
||||||
this.setDataValue('password', hash)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
User.prototype.verifyPassword = function (attempt) {
|
User.prototype.hashPassword = async function (plain) {
|
||||||
if (scrypt.verifyKdfSync(Buffer.from(this.password, 'hex'), attempt)) {
|
return Scrypt.kdf(plain, await Scrypt.pickParams(0.1)).toString('hex')
|
||||||
|
}
|
||||||
|
|
||||||
|
User.prototype.verifyPassword = async function (attempt) {
|
||||||
|
if (await Scrypt.verifyKdf(Buffer.from(this.password, 'hex'), attempt)) {
|
||||||
return this
|
return this
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
User.associate = function (models) {
|
User.associate = function (models) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user