2023-06-27 16:23:18 +00:00
|
|
|
import { HashDriverContract } from '@ioc:Adonis/Core/Hash';
|
2023-03-03 15:54:28 +00:00
|
|
|
// const bcrypt = require("bcrypt");
|
2023-06-27 16:23:18 +00:00
|
|
|
import bcrypt from 'bcryptjs';
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
const saltRounds = 10;
|
|
|
|
export class LaravelHash implements HashDriverContract {
|
|
|
|
public async make(value: string) {
|
|
|
|
const _hashedValue = bcrypt.hashSync(value, saltRounds);
|
|
|
|
return _hashedValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async verify(hashedValue: string, plainValue: string) {
|
|
|
|
let newHash: string;
|
2023-06-27 16:23:18 +00:00
|
|
|
if (hashedValue.includes('$2y$10$')) {
|
|
|
|
newHash = hashedValue.replace('$2y$10$', '$2a$10$');
|
2023-03-03 15:54:28 +00:00
|
|
|
} else {
|
|
|
|
newHash = hashedValue;
|
|
|
|
}
|
|
|
|
return await bcrypt.compareSync(plainValue, newHash);
|
|
|
|
}
|
2023-06-27 16:23:18 +00:00
|
|
|
}
|