Skip to content

Commit 05e608f

Browse files
committed
feat(UserController): creating hashred password
1 parent a376711 commit 05e608f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
<scope>runtime</scope>
4747
</dependency>
4848

49+
<dependency>
50+
<groupId>at.favre.lib</groupId>
51+
<artifactId>bcrypt</artifactId>
52+
<version>0.10.2</version>
53+
</dependency>
54+
4955
<dependency>
5056
<groupId>org.projectlombok</groupId>
5157
<artifactId>lombok</artifactId>

src/main/java/br/com/leticiamangueira/todolist/user/UserController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.springframework.web.bind.annotation.RequestMapping;
99
import org.springframework.web.bind.annotation.RestController;
1010

11+
import at.favre.lib.crypto.bcrypt.BCrypt;
12+
1113
@RestController
1214
@RequestMapping("/users")
1315
public class UserController {
@@ -24,6 +26,9 @@ public ResponseEntity create(@RequestBody UserModel userModel) {
2426
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Usuário já existe!");
2527
}
2628

29+
var passwordHashred = BCrypt.withDefaults().hashToString(12, userModel.getPassword().toCharArray());
30+
userModel.setPassword(passwordHashred);
31+
2732
var userCreated = this.userRepository.save(userModel);
2833
return ResponseEntity.status(HttpStatus.CREATED).body(userCreated);
2934
}

0 commit comments

Comments
 (0)