Skip to content
Snippets Groups Projects
Commit 413a8ecf authored by Nabilsenko's avatar Nabilsenko
Browse files

fix: fixed hash

parent 177272e6
No related branches found
No related tags found
1 merge request!10Password haching
......@@ -15,7 +15,7 @@ import { JwtStrategy } from './jwt.strategy';
PassportModule,
JwtModule.register({
secret: jwtConstants.secret,
signOptions: { expiresIn: '300s' },
signOptions: { expiresIn: '3600s' },
}),
],
controllers: [LoginController],
......
......@@ -25,18 +25,21 @@ export class PeopleDao {
private readonly _peopleModel: Model<People>,
) {}
login = (email: string, password: string): Promise<People | void> =>
new Promise((resolve, reject) => {
this._peopleModel.findOne(
{ email: email, passwordHash: password },
(err, value) => {
if (err) reject(err.message);
if (!value)
reject(new NotFoundException('Email or password is incorrect!'));
resolve(value);
},
);
});
login = async (email: string, password: string): Promise<People | void> => {
try {
const user = await this._peopleModel.findOne({ email });
if (!user) {
throw new NotFoundException('Email or password is incorrect!');
}
const isPasswordCorrect = await bcrypt.compare(password, user.passwordHash);
if (!isPasswordCorrect) {
throw new NotFoundException('Email or password is incorrect!');
}
return user;
} catch (error) {
throw error;
}
};
find = (): Promise<People[]> =>
new Promise((resolve, reject) => {
......@@ -109,7 +112,7 @@ export class PeopleDao {
let secret = '';
for (let index = 0; index < length; index++)
secret += alphabet.charAt(randomInt(alphabet.length));
const saltOrRounds = 10;
const hash = await bcrypt.hash(secret, saltOrRounds);
console.log(secret);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment