Skip to content

Commit 54058b4

Browse files
committed
bcrypt passwords on DB save user
1 parent 4c792be commit 54058b4

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ dependencies {
2727

2828
runtimeOnly 'org.postgresql:postgresql'
2929

30+
// pw encrypt/decrypt
31+
implementation 'org.mindrot:jbcrypt:0.4'
32+
3033
// hateoas
3134
implementation 'org.springframework.hateoas:spring-hateoas:1.5.2'
3235

img/hateoas.png

23.8 KB
Loading

src/main/java/link/hiroshisprojects/kaput/user/UserServiceImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import javax.validation.ConstraintViolationException;
66

7+
import org.mindrot.jbcrypt.BCrypt;
78
import org.springframework.stereotype.Service;
89

910
@Service
@@ -17,6 +18,9 @@ public UserServiceImpl(UserDao userDao) {
1718

1819
@Override
1920
public User save(User user) throws ConstraintViolationException {
21+
String encrypted = BCrypt.hashpw(user.getPassword(), BCrypt.gensalt(10));
22+
user.setPassword(encrypted);
23+
2024
return userDao.save(user);
2125
}
2226

0 commit comments

Comments
 (0)