CoreID/app/models/auth/AppPassword.model.js
2020-08-13 01:56:33 -05:00

29 lines
740 B
JavaScript

const { Model } = require('flitter-orm')
const bcrypt = require('bcrypt')
const uuid = require('uuid').v4
class AppPasswordModel extends Model {
static get schema() {
return {
hash: String,
created: { type: Date, default: () => new Date },
expires: Date,
active: { type: Boolean, default: true },
name: String,
uuid: { type: String, default: uuid },
}
}
async set_hash(password) {
this.hash = await bcrypt.hash(password, 10)
if ( !this.uuid ) this.uuid = uuid()
return this
}
async verify(password) {
return bcrypt.compare(password, this.hash)
}
}
module.exports = exports = AppPasswordModel