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.
24 lines
580 B
24 lines
580 B
4 years ago
|
const { Model } = require('flitter-orm')
|
||
|
const bcrypt = require('bcrypt')
|
||
|
|
||
|
class MFARecoveryCodeModel extends Model {
|
||
|
static get schema() {
|
||
|
return {
|
||
|
code: String,
|
||
|
used: { type: Boolean, default: false },
|
||
|
generated: { type: Date, default: () => new Date },
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static async create(value) {
|
||
|
const code = await bcrypt.hash(value, 10)
|
||
|
return new this({ code })
|
||
|
}
|
||
|
|
||
|
async verify(code) {
|
||
|
return await bcrypt.compare(code, this.code)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = exports = MFARecoveryCodeModel
|