You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CoreID/app/models/auth/AppPassword.model.js

30 lines
768 B

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