-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cookie helper not woking #2848
Comments
Please provide some code examples. We need more to go on then It's not working. |
Here is the my code for setting the cookie if ($remember === 1) {
set_cookie(array(
'name' => getConfig('auth_cookie_id'),
'value' => $this->_user->enc_key,
'expire' => \time() + getConfig('auth_cookie_expiry'),
'httponly' => FALSE
));
// store encrypted key in cookie
set_cookie(array(
'name' => getConfig('auth_cookie_key'),
'value' => $enkey,
'expire' => \time() + getConfig('auth_cookie_expiry'),
'httponly' => FALSE
));
} else {
// set what will be stored in the session
$data = array(
getConfig('auth_session_id') => $this->_user->enc_key,
getConfig('auth_session_key') => $enkey
);
// store data in the session
session()->set($data);
} Here, is where i try to get the cookie data if (get_cookie(getConfig('auth_cookie_id'), TRUE) && get_cookie(getConfig('auth_cookie_key'), TRUE)) {
// store cookie informations in variables
$encryptedUserIDs = get_cookie(getConfig('auth_cookie_id'), TRUE);
echo $enckey = get_cookie(getConfig('auth_cookie_key'), TRUE);
$validate_using = 'cookie';
} else {
// store session informations in variables
$encryptedUserIDs = session()->get(getConfig('auth_session_id'));
$enckey = session()->get(getConfig('auth_session_key'));
$validate_using = 'session';
} |
You might need to double-check your code, then. I modified the default Home controller that ships with the framework to this:
This example doesn't test the Can you be more specific about what's not working? |
Sorry for late comment. Here is the code. namespace App\Libraries;
use App\Models\Remember;
use App\Models\User;
use Config\Services;
class Auth
{
protected $encrypter;
protected $user_model;
protected $remember;
function __construct()
{
\helper('cookie');
$this->encrypter = Services::encrypter();
$this->user_model = new User();
$this->remember = new Remember();
}
public function login($username_email = null, $password = null, $remember_me = false)
{
if (is_null($username_email) || is_null($password))
{
$this->alert->error('Please enter your credentials in the field provided');
return false;
}
$user = $this->user_model->where('email', $username_email)->first();
if (!is_null($user) && $this->verifyPassword($password, $user->password)) {
$save_user_data = $user->id;
if ($encrypt_data = $save_user_data) {
if ($remember_me) {
$data = [
'expires' => strtotime(getConfig('remember_me_expires')),
'persistence' => $encrypt_data,
'selector' => $this->generateToken()
];
return $this->setRememberMe($data);
}
session()->set(['ses_id' => $encrypt_data, 'loggedIn' => true]);
return \true;
}
return \false;
}
return false;
}
public function verifyPassword($pass = null, $hashed_pass = null)
{
return password_verify(
base64_encode(
hash('sha384', $pass, true)
),
$hashed_pass
);
}
public function setRememberMe($data = [])
{
if (\set_cookie(
\getConfig('auth_rememer_name'),
$data['selector'],
$data['expires']
)) {
$this->remember->insert($data);
return true;
}
}
public function checkRememberMe()
{
$cookie = \get_cookie(\getConfig('auth_rememer_name'));
if ($cookie) {
session()->set(['ses_id' => $stored->persistence, 'loggedIn' => true]);
}
}
public function getUser()
{
return $this->user_model->first(session()->ses_id);
}
function generateToken($length = 20)
{
return bin2hex(random_bytes($length));
}
public function is_logged_in()
{
if ($this->checkRememberMe()) {
}
if (session()->loggedIn) {
return true;
}
return false;
}
public function logout()
{
session()->remove(['ses_id', 'loggedIn']);
return true;
}
} Please check it |
@lonnieezell Please help me check this code The Auth Library in order to see where I am getting wrong. Forgive me of tagging your name. I needed this urgently. I have waited but no check on it. And also I can login to my account in the forum. Here is the error |
You cannot login to your forum account? Or you can? If you cannot, let me know the error and I'll see what I can do to get you in, if the password reset feature isn't working. Unfortunately, I cannot review your code here. This is for posting bugs. The forums are where you'll get more eyes on it and more help anyway. |
When I submit my credentials I get this message in return |
It can be anything. For example, CodeIgniter doesn't have a @ChibuezeAgwuDennis if you will find an easy way to recreate the problem, feel free to open a new issue. |
Hello I try to use the cookie system to store some information and also retrieve it I discovered that all the helper is not working.
In my library class fore remember me I try using the
set_cookie()
,get_cookie()
,delete_cookie()
after I have include the cookie helper through the functionhelper('cookie)
. Please I think this is a bug it was working now is not working againThe text was updated successfully, but these errors were encountered: