Skip to content

Commit

Permalink
added api validation to UpdatePasswordDto
Browse files Browse the repository at this point in the history
  • Loading branch information
anishmu20 committed Nov 7, 2024
1 parent 2cee8a5 commit 02ea615
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void deleteMember(@PathVariable int id) {
@PutMapping("/{id}/password")
@PreAuthorize("#id == authentication.principal.memberId")
public ResponseEntity<?> updatePassword(@PathVariable int id,
@RequestBody UpdatePasswordDto updatePasswordDto) {
@Valid @RequestBody UpdatePasswordDto updatePasswordDto) {
memberService.updatePassword(id, updatePasswordDto);
return ResponseEntity.ok("Password updated successfully.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package com.libraryman_api.member.dto;

public class UpdatePasswordDto {
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;

public class UpdatePasswordDto {
private String currentPassword;

@NotBlank(message = "New Password is required")
@Size(min = 8, message = "Password must be at least 8 characters long")
@Pattern(regexp = "^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[@#$%^&+=]).*$",
message = "Password must contain at least one letter, one number, and one special character")
private String newPassword;

public UpdatePasswordDto(String currentPassword, String newPassword) {
Expand Down

0 comments on commit 02ea615

Please sign in to comment.