Insert/create user in database using login form I know its dump question, using login form and insert user in database.

Actually, I have an API that includes users of company/organization and these users already have registered on other applications. So, using such API I can get user info using username and password.

Of course, we need to logged in users directly (without registration) who already have account on other applications.

For logging in, I need to, first, insert the user info in data (before insertion, I can fetch username and password from API) so user can get in the site as logged in user.


After fetching from API, how to create user in the database with
username and password field only?
It should be done without email info.
It is not possible to create a user account in Drupal without writing an email account.

An example of how you can create a user programmatically is:

 $new_user = array(
  'name' =&gt; 'name',
  'mail' =&gt; 'name@email.com',
  'pass' =&gt; 'password', // note: do not md5 the password
  'status' =&gt; 1
 );

 //custom fields
 $new_user-&gt;field_name_lasname['und'][0]['value'] = 'Name and Last Name';
 //custom fields ( custom fields) 
 $new_user-&gt;field_referenced_field_['und'][0]['target_id'] = 0;

 user_save(null, $new_user);


Please excuse me my English is not good