From a729265c7b1f4910c5908e2a19fdd0281a7140d3 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 7 Oct 2015 12:03:17 +0200 Subject: [PATCH] =?utf8?q?Continued:=20-=20added=20new=20exception=20-=20u?= =?utf8?q?pdated=20jars=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- lib/jcontacts-core.jar | Bin 18203 -> 18203 bytes .../DataRepeatMismatchException.java | 39 ++++++++++++++++++ .../jusercore/model/user/LoginUser.java | 21 +++++----- .../mxchange/jusercore/model/user/User.java | 10 ++--- .../jusercore/model/user/UserUtils.java | 25 +++++++++++ 5 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 src/org/mxchange/jusercore/exceptions/DataRepeatMismatchException.java diff --git a/lib/jcontacts-core.jar b/lib/jcontacts-core.jar index ceeaa29af8efe058726733354565e73674c2bba6..3ad2c505af6d74a046a3389439356cf350cc3195 100644 GIT binary patch delta 225 zcmbQ;$2hx>kvG7bnT3mifrEj;&((b*uLiR(kg}M@4B}ms2UDLlK-6S8Mk6pC%xDFs zConpK=_`!3AbPV16AK%dAf#HgRb9iubiHddn7->83#M(|lECyLw@Luy CdqAoH delta 225 zcmbQ;$2hx>kvG7bnT3mifrEizdWG9WUJd4HK+0koGl+Ll9!!1K08x|W7>&SmFryWi zp1|k`rmryCg6Pd6Oe}0*hBSwTBA5}Tsmcvz)R~;(1T(ztwzGg3lUbcDKsHTwaJC2Y zo1FE*^cJ8vNdCRE6PPw}@dDG0E`ebBs*5j}R&@;r)Ag>=VEV3WESR=+O9Io2+$sSs CBuyv) 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 -- 2.39.5