Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a secured "remember me" system using PHP?

I have a login system. How can I implement a secure remember me system using cookies.

What value should I have to store in cookie username and password, but how I can secure it?

like image 553
Saqueib Avatar asked Sep 05 '10 07:09

Saqueib


1 Answers

define A Salt foreach user in db then

on setting

$expire_time = time() + 2 * 7 * 24 * 3600; // 2 weeks exp time

setcookie( 
    "rememberMe",
    crypt($username, $salt),
    $expire_time,
    '/'
);

on validating

$_COOKIE['rememberMe'] === crypt($username, $salt)
like image 127
hesam jaferi Avatar answered Nov 16 '22 03:11

hesam jaferi