import java.text.MessageFormat;
import java.util.Random;
import org.apache.commons.codec.digest.Crypt;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jusercore.container.login.LoginContainer;
/**
return userName;
}
+ /**
+ * Generate a key suitable for confirmation. This is basicly a large and
+ * strong hash with a lop entropy.
+ * <p>
+ * @param user User instance to use as additional entropy source
+ * <p>
+ * @return Generated key
+ */
+ public static String generatedConfirmationKey (final User user) {
+ // Generates random string by creating a random, encrypted password
+ StringBuilder key = new StringBuilder(encryptPassword(generateRandomUserName()));
+
+ // Is user set?
+ if (user instanceof User) {
+ // Add it's name, too
+ key.append(":").append(user); //NOI18N
+
+ // Is user name set?
+ if (user.getUserName() instanceof String) {
+ // Add it
+ key.append(":").append(user.getUserName()); //NOI18N
+ }
+
+ // Is password set?
+ if (user.getUserEncryptedPassword() instanceof String) {
+ // Add it, too
+ key.append(":").append(user.getUserEncryptedPassword()); //NOI18N
+ }
+
+ // Get contact instance
+ Contact contact = user.getUserContact();
+
+ // Is contact set?
+ if (contact instanceof Contact) {
+ // Add it, too
+ key.append(":").append(contact); //NOI18N
+
+ // Is email address set?
+ if (contact.getContactEmailAddress() instanceof String) {
+ // Add it, too
+ key.append(":").append(contact.getContactEmailAddress()); //NOI18N
+ }
+ }
+ }
+
+ // Hash key
+ String hash = DigestUtils.sha256Hex(key.toString());
+
+ // Return it
+ return hash;
+ }
+
/**
* Checks if password from container matches the updatedUser's password
* <p>
- * @param container Container holding user instance and unencrypted password
+ * @param container Container holding user instance and unencrypted password
* @param updatedUser Updated user instance from database
* <p>
* @return Whether the password matches