@Override
    public User createUser(String username, String password, String name, String email)
            throws UserAlreadyExistsException
    {
        try {
            loadUser(username);
            // The user already exists since no exception, so:
            throw new UserAlreadyExistsException("Username " + username + " already exists");
        }
        catch (UserNotFoundException unfe) {
            // The user doesn't already exist so we can create a new user
            Date now = new Date();
            Connection con = null;
            PreparedStatement pstmt = null;
            try {
                con = DbConnectionManager.getConnection();
                pstmt = con.prepareStatement(INSERT_USER);
                pstmt.setString(1, username);
                if (name == null || name.matches("\\s*")) {
                    pstmt.setNull(2, Types.VARCHAR);
                }
                else {
                    pstmt.setString(2, name);
                }
                if (email == null || email.matches("\\s*")) {
                    pstmt.setNull(3, Types.VARCHAR);
                }
                else {
                    pstmt.setString(3, email);
                }
                pstmt.setString(4, StringUtils.dateToMillis(now));
                pstmt.setString(5, StringUtils.dateToMillis(now));
                pstmt.execute();
            }
            catch (SQLException e) {
                throw new RuntimeException(e);
            }
            finally {
                DbConnectionManager.closeConnection(pstmt, con);
            }
            try {
                AuthFactory.setPassword(username, password);
            } catch(Exception e) {
                Log.error("User pasword not set", e);
            }
            
            return new User(username, name, email, now, now);
        }
    }
Default implementation of the UserProvider interface, which reads and writes data
from the {@code ofUser} database table.<p>

Passwords can be stored as plain text, or encrypted using Blowfish. The
encryption/decryption key is stored as the Openfire property {@code passwordKey},
which is automatically created on first-time use. It's critical that the password key
not be changed once created, or existing passwords will be lost. By default
passwords will be stored encrypted. Plain-text password storage can be enabled
by setting the Openfire property {@code user.usePlainPassword} to {@code true}.

@author Matt Tucker
xmppserver/src/main/java/org/jivesoftware/openfire/user/DefaultUserProvider.java