--- /dev/null
+/*
+ * 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);
+ }
+}
import java.util.Calendar;
import javax.persistence.Basic;
+import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
/**
* 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;
/**
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
// 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());
}
@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;
}
}
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);
}
*/
package org.mxchange.jusercore.model.user;
+import org.apache.commons.codec.digest.Crypt;
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