duanmengmiezen8855 2013-12-24 15:38
浏览 133

PHP使用MD5保护$ _GET函数

I'm using a $_GET function in php to perform functions for my Java server.

The website is similar to this: http://api.somewebsite.com/perform/function.php?authkey1=randomMD5&authkey2=randomMD5&parameters=something

Where the variables authkey1 and authkey2 represent a randomly generated MD5. The PHP script does connect to MySQL, and I've already prevented injection. However, before anything else gets parsed by the code, the URL has to include those 2 authkeys or else they get a message saying, "Improper authentication".

Here's an example of what my code does:

// Security key check
$key1 = "skghlskfhgj42u6928749856478937683471095sndgfnsvnrandom";
$key2 = "dbnksgh794ytowhjklgn934ngmsnnmlrj9096345u075u80375ngsr";

$g_key1 = $_GET['authkey1'];
$g_key2 = $_GET['authkey2'];

if (empty($g_key1) || empty($g_key2)) {
die("Improper authorization");
}

if ($g_key1 != $key1 || $g_key2 != $key2) {
die("Improper authorization");
}

// If authentication passes, move on to other functions

Is this method secure or not? Thanks!

  • 写回答

2条回答 默认 最新

  • doulingzhuang3079 2013-12-24 16:03
    关注

    No, that method is not secure, but rather "security by obscurity".

    First and most important, use TLS/SSL. Second, find a 3rd party library to handle request authentication for you. I couldn't find one that did what I needed, so I put one together myself.

    The library is called Query Auth and I wrote it to handle this exact use case. It's a generic implementation of the Signature Version 2 implementation from the AWS SDK for PHP 2. It handles API key and API secret generation, signature creation and validation, and can optionally protect against replay attacks. Documentation and an example implementation are available.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题