Sometime, we need to overide the existing procedure to add user in joomla. So, I'm attach my code below howto add user. You may used my code to create your own component.
Sometimes, we as developer required to extend Joomla function that another extend that what they provide required modification. Below I show how to update your own sql to change user type based on Joomla setting.