throw new IllegalArgumentException("container.userPassword is empty"); //NOI18N
}
+ // Call below method
+ return ifPasswordMatches(container.getUserPassword(), updatedUser);
+ }
+
+ /**
+ * Checks if direct password the updatedUser's password
+ * <p>
+ * @param unencryptedPassword Unencrypted (direct) password
+ * @param updatedUser Updated user instance from database
+ * <p>
+ * @return Whether the password matches
+ */
+ public static boolean ifPasswordMatches (final String unencryptedPassword, final User updatedUser) {
+ // Validate parameters
+ if (null == unencryptedPassword) {
+ // Throw NPE
+ throw new NullPointerException("unencryptedPassword is null"); //NOI18N
+ } else if (unencryptedPassword.isEmpty()) {
+ // NPE for user in container
+ throw new NullPointerException("unencryptedPassword is empty."); //NOI18N
+ } else if (null == updatedUser) {
+ // And again NPE ...
+ throw new NullPointerException("updatedUser is null"); //NOI18N
+ }
+
// First encrypt password
- String encryptedPassword = Crypt.crypt(container.getUserPassword(), updatedUser.getUserEncryptedPassword());
+ String encryptedPassword = Crypt.crypt(unencryptedPassword, updatedUser.getUserEncryptedPassword());
// Is it matching?
return encryptedPassword.equals(updatedUser.getUserEncryptedPassword());
throw new IllegalArgumentException("container.userPassword is empty"); //NOI18N
}
- // First encrypt password
- String encryptedPassword = Crypt.crypt(container.getUserPassword(), container.getUser().getUserEncryptedPassword());
-
- // Is it matching?
- return encryptedPassword.equals(container.getUser().getUserEncryptedPassword());
+ // Call other method
+ return ifPasswordMatches(container.getUserPassword(), container.getUser());
}
/**