I can't find it anywhere in the documentation of Code Igniter - Community Auth how to check user credentials by using simple function. I want to just call a function.
Example: checkIfValid('username', 'mypassword123')
$uid = array_key_exists('uid', $_POST) ? (empty($_POST['uid']) ? '' : $_POST['uid']) : '';
$pwd = array_key_exists('pwd', $_POST) ? (empty($_POST['pwd']) ? '' : $_POST['pwd']) : '';
if ($uid == '' || $pwd == '') { echo $error_response; return; };
$auth_model = $this->authentication->auth_model;
// HOW CAN I LOGIN WITH BOTH USERNAME AND PASSWORD LIKE CALLING A FUNCTION? THIS CODE ONLY LOGS IN USER UID ONLY
$auth_data = $this->{$auth_model}->get_auth_data($uid);
if ($auth_data) {
$this->authentication->maintain_state($auth_data);
echo 'login';
return;
}
On your controller Authentication takes place here
$this->load->library('authentication');
$res = $this->authentication->login( $requirement, $user_string, $passwd ); // requirement is user level
if ($res)
{
echo "User authenticated"; // or do something here
}
else
{
print_r($res); // or do something what ever
}
I'm not sure but try this.
// Get normal authentication data using username or password
if( $auth_data = $this->{$auth_model}->get_auth_data( $uid,$pwd ) )
{
/**
* If redirect param exists, user redirected there.
* This is entirely optional, and can be removed if
* no redirect is desired.
*/
$_GET['redirect'] = 'somewhere';
$this->authentication->redirect_after_login();
// Set auth related session / cookies
$this->authentication->maintain_state( $auth_data );
}
}
else
{
echo 'Example requires that you set a username or password.';
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.