That should be placed in your Auth class. Please review everything line-by-line as this might be outdated.
public function loginOnForum($username, $password, $redirect=false) {
global $db, $cache, $config, $template, $phpEx, $user, $phpbb_root_path, $auth;
$this->startSession();
if($user->data['is_registered']) {
//User is already logged in
} else {
$login = $this->api->db->dsql()
->table('User')
->field('Name')
->where('Email', $username)
->do_getOne();
$password = $this->encryptPassword($password);
$result = $auth->login($login, $password);
if ($result['status'] == LOGIN_SUCCESS) {
$this->api->memorize('sid', append_sid('index.php'));
$this->api->memorize('session_id', $user->session_id);
$this->api->memorize('s_user_id', $user->data['user_id']);
//User was successfully logged into phpBB
if (!$redirect) {
$this->loginRedirect();
}
} else {
//User's login failed
return false;
private function logoutFromForum() {
global $SID, $_SID, $db, $cache, $config, $template, $phpEx, $user, $phpbb_root_path;
$this->startSession();
$user->session_id = $this->api->recall('session_id');
$user->data['user_id'] = $this->api->recall('s_user_id');
$user->session_kill();
$user->session_begin();
$message = $user->lang['LOGOUT_REDIRECT'];
}
function processLogin(){
$this->memorizeOriginalURL();
$form=$this->form=$this->api->add('FreeForm',null,'LoginMenu',array('login_form','_top'));
if($form->isSubmitted()){
if($this->verifyCredintials(
$form->get('username'),
$this->encryptPassword($form->get('password'))
)){
$this->loggedIn($form->get('username'),$this->encrypt($form->get('password')),
$form->get('memorize')=='Y');
$this->memorize('info',$this->info);
$this->generateToken();
if (!$this->loginOnForum($form->get('username'), $form->get('password'))) {
$this->displayError($form);
}
} else {
$this->displayError($form);
}
}
}
function logout() {
$this->logoutFromForum();
// Forces logout. This also cleans cookies
$this->forget('info');
setcookie($this->name."_username",null);
setcookie($this->name."_password",null);
session_destroy();
$this->info=false;
$this->logoutFromSupport();
$this->api->redirect($this->api->getIndexPage());
}