Skip to content

Commit

Permalink
✨ feat(UserRes.java): Add phone and email masking for privacy in us…
Browse files Browse the repository at this point in the history
…er responses.
  • Loading branch information
vnobo committed Feb 27, 2025
1 parent 857a134 commit 9bba1b9
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ public class UserRes extends User {
@ReadOnlyProperty
private Double rank;

@Override
public String getPhone() {
String phone = super.getPhone();
return phone != null && phone.length() >= 7 ?
phone.replaceAll("(\\d{3})\\d{4}(\\d*)", "$1****$2") :
phone;
}

@Override
public String getEmail() {
String email = super.getEmail();
if (email != null && email.contains("@")) {
String[] parts = email.split("@");
String username = parts[0];
String domain = parts[1];
if (username.length() > 2) {
username = username.substring(0, 2) + "****";
}
return username + "@" + domain;
}
return email;
}

/**
* Creates a UserRes instance from a given User object.
*
Expand Down

0 comments on commit 9bba1b9

Please sign in to comment.