📄 00000016.htm
字号:
} <BR> // <BR> // Take a ($ticket) string generated by makeauth(), and a ($time), <BR> // and verify that the ticket is valid and not expired. <BR> // <BR> // If ($time) is 0, the current time will be used. <BR> // <BR> // On error, the function returns the empty string "", <BR> // $authenticated is 0, and $autherr contains the reason <BR> // the authentication failed. <BR> // <BR> // On success, the identity encoded in the ticket is returned, <BR> // $authenticated is non-zero, and $autherr is to be ignored. <BR> // <BR> function checkauth($ticket, $time) <BR> { <BR> global $REMOTE_ADDR; <BR> $this->zerodata(); <BR> if ($time == 0) <BR> $time = time(); <BR> /* <BR> * Item order: hash time realm remote_addr identity <BR> */ <BR> $ticket_items = explode( ":", $ticket); <BR> /* <BR> * if the remote address doesn't match the one in the ticket, <BR> * drop them. <BR> */ <BR> if ($ticket_items[3] != $REMOTE_ADDR) { <BR> $this->autherr = "Address mismatch"; <BR> return ""; <BR> } <BR> // <BR> // if we are supposed to check for expired tickets, do that <BR> // here. <BR> // <BR> if ($this->lifetime != 0) <BR> if ($time > (int)$ticket_items[1] + $this->lifetime) { <BR> $this->autherr = "Ticket expired"; <BR> return ""; <BR> } <BR> // <BR> // make certain that the ticket is not being used before <BR> // it was issued. <BR> // <BR> if ($time < (int)$ticket_items[1]) { <BR> $this->autherr = "Ticket used before issued"; <BR> return ""; <BR> } <BR> // <BR> // verify that the realms match <BR> // <BR> if ($this->realm != $ticket_items[2]) { <BR> $this->autherr = "Realm mismatch"; <BR> return ""; <BR> } <BR> // <BR> // This could be done better... Reassemble the components <BR> // of the ticket passed to us, and rehash. Compare this <BR> // to the hash we were sent. <BR> // <BR> $tmp_items[] = $ticket_items[1]; <BR> $tmp_items[] = $ticket_items[2]; <BR> $tmp_items[] = $ticket_items[3]; <BR> $tmp_items[] = $ticket_items[4]; <BR> $tmp_ticket = implode($tmp_items, ":"); <BR> $hash = md5($this->secret . $tmp_ticket); <BR> if ($hash != $ticket_items[0]) { <BR> $this->autherr = "Integrity check failed"; <BR> return ""; <BR> } <BR> // <BR> // well, it all checks out. Might as well claim we know <BR> // who this person is. <BR> // <BR> $this->hash = $hash; <BR> $this->issue = $ticket_items[1]; <BR> $this->remote_addr = $ticket_items[3]; <BR> $this->identity = $ticket_items[4]; <BR> $this->authenticated = 1; <BR> return $this->identity; <BR> } <BR>}; <BR>?> <BR> <BR>-- <BR> <BR>人生到处知何似? <BR> 应似飞鸿踏雪泥。 <BR> 泥上偶然留指爪, <BR> 鸿飞那复计东西! <BR> <BR> <BR>※ 来源:·BBS 水木清华站 smth.org·[FROM: 162.105.37.191] <BR><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -