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 }, accessed: 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