0

I want to create users in database with md5 password, but I don't have idea, how to do it best. I am using JSF (+PrimeFaces) and JPA. Pieces of code:

registration.xhml:

 <p:password id="password" value="#{userBean.password}" match="repeatPassword" required="true" label="Password"> <f:validateLength minimum="8" /> </p:password>

UserBean:

@ManagedBean
@RequestScoped
public class UserBean {
private String password; 

 public String getPassword() {
    return password;
}

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

    User user = new User();
    user.setFirstName(firstName);
    user.setLastName(lastName);
    user.setEmail(email);
    user.setPassword(password);
    dao.addUser(user);
}

User

@Entity
@Table(name = "users")
public class User implements Serializable {
private String password;

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Blackq
  • 37
  • 1
  • 6
  • Don't use MD5 for password storage. It is too weak and can be cracked too easily for anyone getting hold of the database. Current best practice is to use pbkdf2 or bcrypt. – Anders Abel Dec 15 '15 at 15:43
  • It does not matter, I need a solution for this. – Blackq Dec 15 '15 at 15:47
  • 2
    It's up to you if you want to use MD5 or not, but I thought I'd better inform you that it is no longer considered secure. You've been warned. If you still want to use it I can't stop you - just go ahead. – Anders Abel Dec 15 '15 at 15:54
  • Just generate your MD5 from password, set it to entity and persist. http://stackoverflow.com/questions/415953/how-can-i-generate-an-md5-hash. This question is not related to any technology, just generating hash in java. – Geinmachi Dec 15 '15 at 15:56
  • This question is not java-se, jsf or jpa related... Next time please search a good basic tutorial online. And if you have such a basic question, I doubt you can create a secure AAA framework. Just use an existing one like picketlink or shiro or... – Kukeltje Dec 15 '15 at 16:15

0 Answers0