Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Web API身份验证_Php_Mysql_Api_Authentication - Fatal编程技术网

Php Web API身份验证

Php Web API身份验证,php,mysql,api,authentication,Php,Mysql,Api,Authentication,我一直试图在我将要开发的API上进行身份验证 我试图想出一种成功验证用户身份的方法,记住用户可以访问客户端上的所有数据,我想到了这个想法 Client sends username and password to the server Server checks if they match a user. If it does, we create a hashed string with user_id+e-mail+currentTime+salt and stores th

我一直试图在我将要开发的API上进行身份验证

我试图想出一种成功验证用户身份的方法,记住用户可以访问客户端上的所有数据,我想到了这个想法

Client sends username and password to the server
Server checks if they match a user.
    If it does, we create a hashed string with user_id+e-mail+currentTime+salt
    and stores this in a database-table with an expiration date.
Server returns hashed string to client

Client sends random request to server including key
Server checks if key is correct and if it's expired

这是一种安全的方法吗,或者你看到了任何安全漏洞吗?

首先,
我看到了安全漏洞吗?
是和否。如果你没有使用安全连接,通过网络发送用户密码和用户名将不是一个好主意。特别是如果您没有在sha512或任何您使用的文件中对用户密码进行哈希运算

我会在客户端散列密码,然后发送它

以Twitter的API为例。他们也使用密钥来验证您的帐户


以下是一个有用的方法。

如何防止有人劫持密钥并代表用户发出请求?我想只有当有人在同一网络上并嗅探到密钥时,这才可能实现,在这种情况下,直到密钥过期为止。你对如何让它更安全有什么想法吗?@Pixark我的回答显示了一种更安全的方法。如果你对自己的实现没有信心,请不要重新发明轮子。看看oauth。