Skip to content

Commit

Permalink
Put input validation before field assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius Klepp authored and Marius Klepp committed Feb 12, 2026
1 parent 3665e4d commit 723099e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main/java/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ public class User {
private final PasswordHash password;

public User(String userName, String phoneNumber, PasswordHash password, String eMail) {
this.userName = userName;
this.phoneNumber = phoneNumber;
this.eMail = eMail;
this.password = password;

if ( userName == null || userName.isBlank() ) {
throw new IllegalArgumentException("Username has to be filled in");
}
Expand All @@ -23,12 +18,17 @@ public User(String userName, String phoneNumber, PasswordHash password, String e
}

if ( phoneNumber == null || phoneNumber.isBlank() ) {
throw new IllegalArgumentException("Phonenumber has to be filled in");
throw new IllegalArgumentException("Phone number has to be filled in");
}

if ( phoneNumber.length() != 8 ) {
throw new IllegalArgumentException("Fill in a phonenumber with 8 digits");
throw new IllegalArgumentException("Fill in a phone number with 8 digits");
}

this.userName = userName;
this.phoneNumber = phoneNumber;
this.eMail = eMail;
this.password = password;
}

public String getUsername() { return userName; }
Expand Down

0 comments on commit 723099e

Please sign in to comment.