NestJs 회원가입 관련 개인 학습내용
Salt를 해야하는 이유
Salt를 해야하는 이유Bcrypt 이용
yarn add bcrypt
yarn add @types/bcrypt -Dbcrypt.hash(myPlaintextPassword, saltRounds, function(err, hash) {
// hash데이터가 반환됨.
});Last updated
Salt를 해야하는 이유yarn add bcrypt
yarn add @types/bcrypt -Dbcrypt.hash(myPlaintextPassword, saltRounds, function(err, hash) {
// hash데이터가 반환됨.
});Last updated
import * as bcrypt from 'bcrypt'
...
bcrypt.hash(data.password, 10) // Hash 암호화
result ::: $2b$10$pBK.Bzu7DXNy7voxNdSiwObaf1Tlwet3NzRNNg3qWtLITRp/M9w.2bcrypt.compareSync(plainString, hashString)
// member.service
async signInMember(data: SigninMemberDto): Promise<boolean> {
const member = await this.repo.findOne({
where: {
email: data.email,
},
});
if (!member) {
throw new HttpException('유저가 없습니다.', HttpStatus.NOT_FOUND);
}
const isCompare = await bcrypt.compare(data.password, member.password);
if (!isCompare) {
throw new HttpException(
'이메일 또는 암호가 틀렸습니다.',
HttpStatus.UNAUTHORIZED,
);
}
return isCompare;
}