auth: add hash function

the hash function uses bcrypt with 2^16 iterations.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-01-17 14:32:17 +01:00 committed by David Mehren
parent b589dedd2a
commit 667cf7e915
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
3 changed files with 44 additions and 3 deletions

View file

@ -12,6 +12,7 @@ import { ConsoleLoggerService } from '../logger/console-logger.service';
import { UserInfoDto } from './user-info.dto';
import { User } from './user.entity';
import { AuthToken } from './auth-token.entity';
import { hash } from 'bcrypt'
import crypt from 'crypto';
import { AuthTokenDto } from './auth-token.dto';
import { AuthTokenWithSecretDto } from './auth-token-with-secret.dto';
@ -71,6 +72,11 @@ export class UsersService {
return user;
}
async hashPassword(password: string): Promise<string> {
// hash the password with bcrypt and 2^16 iterations
return hash(password, 16)
}
async getUserByAuthToken(token: string): Promise<User> {
const accessToken = await this.authTokenRepository.findOne({
where: { accessToken: token },