From: Roland Haeder Date: Wed, 7 Oct 2015 10:03:17 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a729265c7b1f4910c5908e2a19fdd0281a7140d3;p=juser-activity-core.git Continued: - added new exception - updated jars Signed-off-by:Roland Häder --- diff --git a/lib/jcontacts-core.jar b/lib/jcontacts-core.jar index ceeaa29..3ad2c50 100644 Binary files a/lib/jcontacts-core.jar and b/lib/jcontacts-core.jar differ diff --git a/src/org/mxchange/jusercore/exceptions/DataRepeatMismatchException.java b/src/org/mxchange/jusercore/exceptions/DataRepeatMismatchException.java new file mode 100644 index 0000000..50519aa --- /dev/null +++ b/src/org/mxchange/jusercore/exceptions/DataRepeatMismatchException.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2015 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jusercore.exceptions; + +/** + * An exception thrown when the user has not entered same email addresses + *

+ * @author Roland Haeder + */ +public class DataRepeatMismatchException extends Exception { + + /** + * Serial number + */ + private static final long serialVersionUID = 12_857_813_986_248_156L; + + /** + * Constructor with message + *

+ * @param message Message to show + */ + public DataRepeatMismatchException (final String message) { + super(message); + } +} diff --git a/src/org/mxchange/jusercore/model/user/LoginUser.java b/src/org/mxchange/jusercore/model/user/LoginUser.java index f066460..8284842 100644 --- a/src/org/mxchange/jusercore/model/user/LoginUser.java +++ b/src/org/mxchange/jusercore/model/user/LoginUser.java @@ -18,6 +18,7 @@ package org.mxchange.jusercore.model.user; import java.util.Calendar; import javax.persistence.Basic; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; @@ -61,8 +62,8 @@ public class LoginUser implements User { /** * Id number from "contacts" table */ - @JoinColumn (name = "contact_id", nullable = false, updatable = false, unique = true) - @OneToOne (targetEntity = UserContact.class, optional = false) + @JoinColumn (name = "contact_id", nullable = false, updatable = false) + @OneToOne (cascade = CascadeType.ALL, targetEntity = UserContact.class, optional = false) private Contact userContact; /** @@ -109,10 +110,10 @@ public class LoginUser implements User { private String userName; /** - * Password hash + * Encrypted password */ - @Column (name = "user_password_hash") - private String userPasswordHash; + @Column (name = "user_encrypted_password", nullable = false) + private String userEncryptedPassword; /** * Default constructor @@ -128,7 +129,7 @@ public class LoginUser implements User { // Copy other data this.setUserConfirmKey(user.getUserConfirmKey()); this.setUserName(user.getUserName()); - this.setUserPasswordHash(user.getUserPasswordHash()); + this.setUserEncryptedPassword(user.getUserEncryptedPassword()); this.setUserAccountStatus(user.getUserAccountStatus()); this.setUserCreated(user.getUserCreated()); this.setUserLocked(user.getUserLocked()); @@ -205,12 +206,12 @@ public class LoginUser implements User { } @Override - public String getUserPasswordHash () { - return this.userPasswordHash; + public String getUserEncryptedPassword () { + return this.userEncryptedPassword; } @Override - public void setUserPasswordHash (final String userPasswordHash) { - this.userPasswordHash = userPasswordHash; + public void setUserEncryptedPassword (final String userEncryptedPassword) { + this.userEncryptedPassword = userEncryptedPassword; } } diff --git a/src/org/mxchange/jusercore/model/user/User.java b/src/org/mxchange/jusercore/model/user/User.java index 6c4f7d0..7513d3a 100644 --- a/src/org/mxchange/jusercore/model/user/User.java +++ b/src/org/mxchange/jusercore/model/user/User.java @@ -134,16 +134,16 @@ public interface User extends Serializable { public void setUserName (final String customerNumber); /** - * Getter for password hash + * Getter for encrypted password *

- * @return Password hash + * @return Encrypted password */ - public String getUserPasswordHash (); + public String getUserEncryptedPassword (); /** * Setter for password hash *

- * @param customerPasswordHash Password hash + * @param userEncryptedPassword Encrypted password */ - public void setUserPasswordHash (final String customerPasswordHash); + public void setUserEncryptedPassword (final String userEncryptedPassword); } diff --git a/src/org/mxchange/jusercore/model/user/UserUtils.java b/src/org/mxchange/jusercore/model/user/UserUtils.java index de555f9..32cdaa5 100644 --- a/src/org/mxchange/jusercore/model/user/UserUtils.java +++ b/src/org/mxchange/jusercore/model/user/UserUtils.java @@ -16,6 +16,7 @@ */ package org.mxchange.jusercore.model.user; +import org.apache.commons.codec.digest.Crypt; import org.mxchange.jcore.BaseFrameworkSystem; /** @@ -24,6 +25,30 @@ import org.mxchange.jcore.BaseFrameworkSystem; * @author Roland Haeder */ public class UserUtils extends BaseFrameworkSystem { + /** + * Length of salt + */ + private static final int SALT_LENGTH = 10; + + /** + * Hashes given user password and adds a salt to it + *

+ * @param userPassword User password to be hashed + * @return Hashed user password + */ + public static String encryptPassword (final String userPassword) { + // Generate large number + String number = Long.toString(Math.round(Math.random() * 10_000_000_000L)); + + // Generate salt + String salt = Crypt.crypt(number); + + // First encrypt password + String encryptedPassword = Crypt.crypt(userPassword, salt); + + // Return it + return encryptedPassword; + } /** * No instance from this class