dongwupu5991 2014-09-06 10:30
浏览 75

为cookie创建验证密钥

I've working on secure cookies for all users and a fast way to verify them.

This is what i come up with:

When you register a user a salt is generated into the database for each user.

When you log in set these two cookies:

$_COOKIE["key"] and $_COOKIE["user"]

$_COOKIE["user"] is the ID of the user that logged in.

The $_COOKIE["key"] is set like this: sha1(sha1($id).sha1($salt));

and then to verify the cookies i created this function:

public function check_cookie(){


    //CHECK IF THE COOKIE IS MATCHING THE HASHKEY AND IF USER IS CONTAINING NUMBERS
    if(sha1(sha1($_COOKIE["user"]).sha1($salt)) != $_COOKIE["key"] || 
!is_numeric($_COOKIE["user"])){

        //REMOVE COOKIES 
        setcookie('user', null, -1);
        setcookie('key', null, -1);

        return FALSE;

    } else {

        return TRUE;

    }

}

Is this a secure way to do it? Do you see any fault in this way of structure?

Thanks in advance!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 linux驱动,linux应用,多线程
    • ¥20 我要一个分身加定位两个功能的安卓app
    • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
    • ¥15 IAR程序莫名变量多重定义
    • ¥15 (标签-UDP|关键词-client)
    • ¥15 关于库卡officelite无法与虚拟机通讯的问题
    • ¥15 目标检测项目无法读取视频
    • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
    • ¥100 求采集电商背景音乐的方法