]> git.mxchange.org Git - juser-login-core.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Wed, 7 Oct 2015 10:03:17 +0000 (12:03 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 7 Oct 2015 10:03:17 +0000 (12:03 +0200)
- added new exception
- updated jars
Signed-off-by:Roland Häder <roland@mxchange.org>

lib/jcontacts-core.jar
src/org/mxchange/jusercore/exceptions/DataRepeatMismatchException.java [new file with mode: 0644]
src/org/mxchange/jusercore/model/user/LoginUser.java
src/org/mxchange/jusercore/model/user/User.java
src/org/mxchange/jusercore/model/user/UserUtils.java

index ceeaa29af8efe058726733354565e73674c2bba6..3ad2c505af6d74a046a3389439356cf350cc3195 100644 (file)
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 (file)
index 0000000..50519aa
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jusercore.exceptions;
+
+/**
+ * An exception thrown when the user has not entered same email addresses
+ * <p>
+ * @author Roland Haeder
+ */
+public class DataRepeatMismatchException extends Exception {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 12_857_813_986_248_156L;
+
+       /**
+        * Constructor with message
+        * <p>
+        * @param message Message to show
+        */
+       public DataRepeatMismatchException (final String message) {
+               super(message);
+       }
+}
index f06646070447d4df801c21502584d36fc088230c..8284842e3f60dd607c035a60e5a05f60fb1440b3 100644 (file)
@@ -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;
        }
 }
index 6c4f7d0645965853c9712f5a3e49499d42ae343b..7513d3af7562d73296a92dbc7d311726a52c6509 100644 (file)
@@ -134,16 +134,16 @@ public interface User extends Serializable {
        public void setUserName (final String customerNumber);
 
        /**
-        * Getter for password hash
+        * Getter for encrypted password
         * <p>
-        * @return Password hash
+        * @return Encrypted password
         */
-       public String getUserPasswordHash ();
+       public String getUserEncryptedPassword ();
 
        /**
         * Setter for password hash
         * <p>
-        * @param customerPasswordHash Password hash
+        * @param userEncryptedPassword Encrypted password
         */
-       public void setUserPasswordHash (final String customerPasswordHash);
+       public void setUserEncryptedPassword (final String userEncryptedPassword);
 }
index de555f9c1cce87f4e19d89442c8105fa5c5c4c2a..32cdaa55b6cfc6034d366362beff749edfde7d95 100644 (file)
@@ -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
+        * <p>
+        * @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