fjrial
fjrial

Reputation: 23

Codeigniter Tank Auth login as another user

I have parent/childs relation established into tank_auth users..

I need to develop some code to allow parent user to be logged as any of his child users. Also the logout feature when you are logged as child should let you back to your parent session.

I was thinking to implement some methods to alter current session_data in database to change user information from parent to child_user.

This is a current data_session from logged user.. a:4: {s:9:"user_data";s:0:"";s:7:"user_id";s:2:"31";s:8:"username";s:6:"fjrial";s:6:"status";s:1:"1";} Tried to alter this info... just changed user_id and username to something valid, and it seems to work..

What do you think about this? Security concerns? Any other way to accomplish this feature?

[UPDATE] This is, basically what I´m doing for login as another user

$back_session_user_id=$this->session->userdata('user_id');
$back_session_username=$this->session->userdata('username');


$this->session->set_userdata('user_id',$other['user_id']);
$this->session->set_userdata('username',$other['username']);
$this->session->set_userdata('user_id_bak',$back_session_user_id);
$this->session->set_userdata('username_bak',$back_session_username);

$data['user_id']    = $other['user_id'];
$data['username']   = $other['username'];

redirect('welcome',$data);

And this if for loggin out and going back to your previously session

$back_session_user_id=$session_data=$this->session->userdata('user_id_bak');
$back_session_username=$session_data=$this->session->userdata('username_bak');
$this->session->set_userdata('user_id',$back_session_user_id);
$this->session->set_userdata('username',$back_session_username);
$this->session->unset_userdata('user_id_bak');          
$this->session->unset_userdata('username_bak');         

$data['user_id']    = $back_session_user_id;
$data['username']   = $back_session_username;
redirect('welcome',$data);

Upvotes: 2

Views: 326

Answers (0)

Related Questions