Updates
This commit is contained in:
20
lib/auth.ts
20
lib/auth.ts
@@ -1,16 +1,16 @@
|
|||||||
import passport from 'koa-passport';
|
import passport from 'koa-passport';
|
||||||
|
|
||||||
import Users from 'grow-db/lib/models/users';
|
// import Users from 'grow-db/lib/models/users';
|
||||||
import { User } from 'grow-db/lib/schemas/user';
|
// import { User } from 'grow-db/lib/schemas/user';
|
||||||
|
|
||||||
passport.serializeUser((user: User, done) => { done(null, user._id); });
|
// passport.serializeUser((user: User, done) => { done(null, user._id); });
|
||||||
|
|
||||||
passport.deserializeUser(async (id, done) => {
|
// passport.deserializeUser(async (id, done) => {
|
||||||
const user = await Users.findById(id);
|
// const user = await Users.findById(id);
|
||||||
|
|
||||||
if (user) {
|
// if (user) {
|
||||||
done(null, user);
|
// done(null, user);
|
||||||
}
|
// }
|
||||||
|
|
||||||
done('user not found', null);
|
// done('user not found', null);
|
||||||
});
|
// });
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import crypto from 'crypto';
|
import { pbkdf2Sync, randomBytes } from 'crypto';
|
||||||
|
|
||||||
export const encrypt = (password: string) => {
|
export const encrypt = (password: string) => {
|
||||||
const salt = crypto.randomBytes(16).toString('hex');
|
const salt = randomBytes(16).toString('hex');
|
||||||
const hash = crypto.pbkdf2Sync(password, salt, 10000, 512, 'sha512').toString('hex');
|
const hash = pbkdf2Sync(password, salt, 10000, 512, 'sha512').toString('hex');
|
||||||
return `${salt}:${hash}`;
|
return `${salt}:${hash}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const verify = (test: string, secret: string) => {
|
export const verify = (test: string, secret: string) => {
|
||||||
const [salt, hash] = secret.split(':');
|
const [salt, hash] = secret.split(':');
|
||||||
return crypto.pbkdf2Sync(test, salt, 10000, 512, 'sha512').toString('hex') === hash;
|
return pbkdf2Sync(test, salt, 10000, 512, 'sha512').toString('hex') === hash;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user