doumu1951 2011-06-11 18:03
浏览 22

登录脚本和md5字符串比较的问题

The login sript below does not let me log in with triple checked credentials. After thorough testing the problem is narrowed to the comparison of hashed posted password and hashed password from user-table. When echoing the vars they are the same. What have I missed?

Removing password fro mthe pdo select fetch the user.

Echoing the password from the fetched user (fetched as above bullet) and the posted password shows they are in fact the same

BUT still when putting the two passwords in a if-statement posted==fetched it does not approve

if(!empty($_POST['email']) && !empty($_POST['password'])){

    $givenEmail = strip_tags($_POST['email']);
    $givenPassword = md5($_POST['password']);

    //query : standard
    $STH = $DBH->prepare('SELECT * from user where email = :email && password = :password');
    $STH -> bindParam(':email', $givenEmail);
    $STH -> bindParam(':password', $givenPassword);
    try{
        $STH->execute();
        $successFetchUserData=true;
    }catch (PDOException $e){
        echo '<div class="is_error">Något gick fel, vänligen pröva igen om en liten stund.</div>';
        //echo "Fel: " . $e->getMessage();
    }

    if(!empty($successFetchUserData)){

        $userFoundByEmail=$STH->rowCount();

        if($userFoundByEmail>0){

            $ns = rand(10e16, 10e20);
            $randomString = base_convert($ns, 10, 36);

            $STH = $DBH->prepare("INSERT INTO security (ip,token) VALUES (:ip,:token)");
            $STH->bindParam(':ip', $_SERVER['REMOTE_ADDR']);
            $STH->bindParam(':token', $randomString);
            try{
                $STH->execute();
                $sucessSecurity=true;
            }catch (PDOException $e){
                echo '<div class="is_error">Något gick fel, vänligen pröva igen om en liten stund.</div>';
                //echo "Fel: " . $e->getMessage();
            }

            if(!empty($sucessSecurity)){

                $_SESSION['token'] = $randomString;
                $loginGood = true;

            }

        }

    }

}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 个人网站被恶意大量访问,怎么办
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)