Hi,

for some reasons, we decided to use our own database to keep users data.
So i am writting a module for user logins that connects to our database and validates the user.
my problem is, what do i have to do after i validate user credentials (against our database) so that drupal
will use my users data instead of drupal's core database?

I supposed i had to set the global $user's data but so far no luck. here is what i have so far:

                        //fetch user data from our database (to $data)
                        (...)

                        //set the user object details
			global $user;
			$user->uid = $data->id;
			$user->name = $data->username;
			$user->pass = $data->password;
			$user->mail = $data->email;
			$user->created = $data->created;
			$user->access = $last_access;
			$user->status = 1;	//not blocked
			$user->init = $data->email;
			$user->roles = array('2' => 'authenticated user');		//TEMP
			
			//regenerate the session
			sess_regenerate();

As you can imagine, this is not doing the trick... Any guidelines would be greatly appreciated!
If possible i would also like to know what issues i might run into with this approach.

Thank you all

Comments

mradcliffe’s picture

You want to do this within hook_init in your module iirc.

jusaf’s picture

Thanks for the reply!

Could you elaborate a little more? i'm not sure if i'm following you...
i see that hook_init is meant for module initialization, what i need is that when the user submits his credentials via my module's form,
the module will verify the credentials in our database (this part is done) and tell drupal that the user is logged in (that's where i have trouble).
so when hook_init is called, i don't have the user's data yet...

correct me if i'm wrong, i new to drupal... :)