Closed NY1105 closed 11 months ago
Took a look at this bug and successfully replicated this issue in my local environment. Root cause: Missing validation condition for input in the controller class. Solution: Adding jakarta validation library in the Vo class to resolve the problem
Fixed in the next release, closing this issue for now.
private boolean isValidPassword(String password) {
String regex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\W).+$";
return password.matches(regex);
}
public ResponseEntity<User> register(User newUser) {
if (!isValidPassword(newUser.getUserPassword())) {
return ResponseEntity.badRequest().build();
}
User user = user_repository.saveAndFlush(newUser);
return ResponseEntity.status(HttpStatus.CREATED).body(user);
}
Tested
Summary
Validation seems missing for password during user registration Passwords are suppose to have 8+ length, 1+ Special, 1+ Uppercase, 1+ Lowercase
Severity
Major
Reporter
@NY1105
Assignee
@NY1105 @whongam
Product
e-commerce
Component
Backend API -> User
Version
Release 2
Environment
Visual Studio Code
Thunder Client (Equivalent to Postman)
Description
mvn spring-boot:run
to start the serverPOST localhost:8080/user/register
with body:{ "userId": "user123", "userPassword": "pass456" }
Current result:
Status: 200 Ok
{ "userId": "user123", "userPassword": "pass456", "totalSpent": 0.0, "carts": null, "membershipTier": 0 }
Expected result:
Status: 400 Bad Request