def verify_user(user_id, session_id, timestamp, token):
if abs(int(time.time())-int(timestamp)) > 60:
return False
m1 = hashlib.md5()
m1.update(str(user_id).encode('utf8'))
hashcode1 = m1.hexdigest()[8:-8]
m2 = hashlib.md5()
m2.update(str(session_id).encode('utf8'))
hashcode2 = m2.hexdigest()[8:-8]
m3 = hashlib.md5()
m3.update(str(timestamp).encode('utf8'))
hashcode3 = m3.hexdigest()[8:-8]
hashcode = hashcode1[:8] + hashcode2[8:16] + hashcode3[-8:]
if hashcode == token:
return True
else:
return False
网友评论