package com.edify.model;

import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotBlank;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import org.apache.commons.lang.StringUtils;

/**
 * @author: <a href="https://github.com/jarias">jarias</a>
 */
@Entity
@Table(name = "users", uniqueConstraints = {@UniqueConstraint(columnNames = {"username"})})
public class User {
    public static final String[] TABLE_COLUMNS = {"id", "firstName", "lastName", "username"};
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @NotBlank
    @NotNull
    @Email
    private String username;
    @NotNull
    @NotBlank
    private String password;
    @NotNull
    @NotBlank
    private String firstName;
    @NotNull
    @NotBlank
    private String lastName;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @PreUpdate
    @PrePersist
    private void encodePassword() {
        PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        if (StringUtils.isNotBlank(password) && !password.startsWith("$2a$10$")) {
            String hashedPassword = passwordEncoder.encode(password);
            password = hashedPassword;
        }
    }
}

@@ -34,45 +34,39 @@
 org.
-hibernate.validator.cons
+apache.commons.lang.S
 tr
-a
 in
-ts.Ema
+gUt
 il
+s
 ;%0Aim
@@ -110,67 +110,43 @@
 nts.
-NotBlank;%0A%0Aimport javax.persistence.*;%0Aimport javax
+Email;%0Aimport org.hibernate
 .validat
 ion.
@@ -141,19 +141,18 @@
 .validat
-ion
+or
 .constra
@@ -163,14 +163,14 @@
 .Not
-Null;%0A
+Blank;
 %0Aimp
@@ -209,25 +209,29 @@
 .crypto.
-password.
+bcrypt.BCrypt
 Password
@@ -278,37 +278,33 @@
 rity.crypto.
-bcrypt.BCrypt
+password.
 PasswordEnco
@@ -320,43 +320,114 @@
 ort 
-org.apache.commons.lang.S
+javax.persistence.*;%0Aimport javax.validation.constraints.NotNull;%0Aimport javax.validation.cons
 tr
+a
 in
-gUtils
+ts.Size
 ;%0A%0A/
@@ -439,17 +439,16 @@
  @author
-:
  %3Ca href
@@ -876,32 +876,51 @@
 l%0A    @NotBlank%0A
+    @Size(min = 6)%0A
     private Stri

Set min size for password as validation annotation