Skip to content

Commit

Permalink
feat : 회원가입 password salt 암호화 #35
Browse files Browse the repository at this point in the history
  • Loading branch information
GeunH committed Nov 20, 2023
1 parent 53c6502 commit ce98c08
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion be/src/user/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class User {
@Column({ type: "boolean" })
isMale: boolean;

@Column({ type: "varchar", length: 50, nullable: true })
@Column({ type: "varchar", length: 62, nullable: true })
password: string | null;

@Column({ type: "varchar", length: 20, nullable: true })
Expand Down
2 changes: 2 additions & 0 deletions be/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { UserInfoDto } from "./dto/userInfo.dto";
import { InjectRepository } from "@nestjs/typeorm";
import { UserRepository } from "./user.repository";
import { TokenInfo } from "./user.decorator";
import { hashPassword } from "src/utils/encryption.utils";

@Injectable()
export class UserService {
Expand All @@ -11,6 +12,7 @@ export class UserService {
private usersRepository: UserRepository
) { }
async signup(userInfoDto: UserInfoDto) {
userInfoDto.password = await hashPassword(userInfoDto.password);
return await this.usersRepository.createUser(userInfoDto);
}
async getNickNameAvailability(nickName: UserInfoDto["nickName"]) {
Expand Down
9 changes: 9 additions & 0 deletions be/src/utils/encryption.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as bcrypt from 'bcrypt';

export async function hashPassword(password: string): Promise<string> {
return await bcrypt.hash(password, 10);
}

export async function comparePasswords(inputPassword: string, storedPassword: string): Promise<boolean> {
return await bcrypt.compare(inputPassword, storedPassword);
}

0 comments on commit ce98c08

Please sign in to comment.