mirror of
https://github.com/status-im/codimd.git
synced 2025-01-26 21:09:00 +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'
|
||||
// external modules
|
||||
var Sequelize = require('sequelize')
|
||||
var scrypt = require('scrypt')
|
||||
var Scrypt = require('scrypt-kdf')
|
||||
|
||||
// core
|
||||
var logger = require('../logger')
|
||||
@ -41,20 +41,20 @@ module.exports = function (sequelize, DataTypes) {
|
||||
}
|
||||
},
|
||||
password: {
|
||||
type: Sequelize.TEXT,
|
||||
set: function (value) {
|
||||
var hash = scrypt.kdfSync(value, scrypt.paramsSync(0.1)).toString('hex')
|
||||
this.setDataValue('password', hash)
|
||||
}
|
||||
type: Sequelize.TEXT
|
||||
}
|
||||
})
|
||||
|
||||
User.prototype.verifyPassword = function (attempt) {
|
||||
if (scrypt.verifyKdfSync(Buffer.from(this.password, 'hex'), attempt)) {
|
||||
User.prototype.hashPassword = async function (plain) {
|
||||
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
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
User.associate = function (models) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user