Example Analysis of PHP token Verification Generation Principle
- 2021-12-12 04:01:12
- OfStack
In this paper, the principle of PHP token verification generation is described by examples. Share it for your reference, as follows:
<?php
/**
* @Author: Ding Jianlong
* @Date: 2019-03-20 00:38:01
* @Last Modified by: Ding Jianlong
* @Last Modified time: 2019-03-22 17:50:59
*/
// Generate authentication for sending requests token
// Here's key It can be content containing user information, without users + Different permissions
function makeToken($key){
//100 Effective and unchanged within seconds, and the time is adjusted according to actual needs. No. 1 3 Party login authorization 15 God.
return $token = md5($key.sha1(substr(time(),3,7)));
}
// Background similar verification,
function checkToken($key,$token){
$true = md5($key.sha1(substr(time(),3,7)));
if($token == $true){
return true; //token Correct
}else{
return false;
}
}
$key = 'https://github.com/idjl/';
echo $t = makeToken($key);
var_dump(checkToken($key,'259521122'));
var_dump(checkToken($key,$t));
var_dump(checkToken($key,'259521122'));
Run results:
e4ce1a6c66246eee048f11a540bf197ebool(false)
bool(true)
bool(false)
More readers interested in PHP can check the topics of this site: "php Programming Security Tutorial", "php Security Filtering Skills Summary", "PHP Basic Syntax Introduction Tutorial", "php Object-Oriented Programming Introduction Tutorial", "php String (string) Usage Summary", "php+mysql Database Operation Introduction Tutorial" and "php Common Database Operation Skills Summary"
I hope this article is helpful to everyone's PHP programming.