user.setAdmin(admin);
user.setComment(comment);
if (hash != null && salt != null) {
user.setSaltAndHash(getByteArray(salt), getByteArray(hash));
} else if (password != null) {
SHA256 sha = new SHA256();
char[] passwordChars = getCharArray(password);
byte[] userPasswordHash = sha.getKeyPasswordHash(userName, passwordChars);
user.setUserPasswordHash(userPasswordHash);
} else {
throw DbException.throwInternalError();
}
db.addDatabaseObject(session, user);