Springboot_ToyProject - Temporage / Bcrypt, gradle

2020. 2. 2. 00:27학부 프로젝트/Temporage

이전에 미국에 있을때 회원가입할때는 password를 hash해서 저장 및 비교 해야 한다는걸 배웠었다. 그때 기억을 되살려보면서 진행했다.

 

PHP에서 그랬지만 Java 에서도 크게 어렵지는 않았다. 내가 암호화 하는게 아니라 이미 만들어져 있는걸 쓰면 그만이기 때문.

 

Bcrypt 라는걸 이용했는데, 먼저 gradle에

implementation group: 'org.mindrot', name: 'jbcrypt', version: '0.3m' //Bcrypt 암호화

를 추가해 준다. 

 

어떤 의존성을 추가할때는

https://mvnrepository.com/tags/gradle

 

Maven Repository: gradle

Kotlin Gradle Plugin Last Release on Nov 26, 2019

mvnrepository.com

여기서 검색해서 하는게 제일 빠른것 같다. ~~~ repo 이런식으로 google에 검색하면 나오니 참고.

 

 

Bcrypt를 사용하는 목적은 2가지 이다. 목적이라기 보단 사용 방법? 에 가까울지 모르겠다.

 

  1. password의 hash화
  2. hash된 password와 평문 password의 일치 여부 비교

딱 2가지를 해주는 함수만 알면 끝난다.

 

BCrypt.hashpw(password, BCrypt.gensalt()) //return value : hash password

BCrypt.checkpw(password, hashed_password) // return value : boolean

 

실제로 사용한 경우는 다음과 같다.

 

hashing password
hashed 된 password 를 체크