📄 00000016.htm
字号:
<HTML><HEAD> <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>发信人: thinkin (强强), 信区: Linux <BR>标 题: authticket <BR>发信站: BBS 水木清华站 (Thu Feb 17 10:59:25 2000) <BR> <BR><?php <BR>// $Id: authticket.phl,v 1.3 1998/02/11 16:45:34 explorer Exp $ <BR>// <BR>// Copyright (c) 1998 Michael Graff <<A HREF="mailto:explorer@flame.org>">explorer@flame.org></A> <BR>// All rights reserved. <BR>// <BR>// Redistribution and use in source and binary forms, with or without <BR>// modification, are permitted provided that the following conditions <BR>// are met: <BR>// 1. Redistributions of source code must retain the above copyright <BR>// notice, this list of conditions and the following disclaimer. <BR>// 2. Redistributions in binary form must reproduce the above copyright <BR>// notice, this list of conditions and the following disclaimer in the <BR>// documentation and/or other materials provided with the distribution. <BR>// 3. Neither the name of author nor the names of its contributors may be <BR>// used to endorse or promote products derived from this software <BR>// without specific prior written permission. <BR>// <BR>// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY <BR>// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED <BR>// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE <BR>// DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE <BR>// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL <BR>// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR <BR>// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER <BR>// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT <BR>// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY <BR>// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF <BR>// SUCH DAMAGE. <BR>// <BR>class authticket { <BR> var $secret = "setme"; // you WILL want to change this <BR> var $realm = ""; // the realm of this identity <BR> var $lifetime = 2 * 60 *60; // tickets good for 2 hours <BR> var $authenticated = 0; // the data here is valid iff non-zero <BR> var $identity; // the remote identity, if decoded correctly <BR> var $issue; // the time the ticket was issued <BR> var $remote_addr; // the remote address of the client <BR> var $hash; // the hash value. Probably of little use. <BR> var $autherr; // if verification faild, this contains why <BR> // <BR> // helper function which just zeros out the ticket data <BR> // <BR> function zerodata() <BR> { <BR> $this->authenticated = 0; <BR> $this->identity = ""; <BR> $this->issue = 0; <BR> $this->remote_addr = ""; <BR> $this->hash = ""; <BR> $this->autherr = ""; <BR> } <BR> // <BR> // Take a string ($identity) and a time ($time) and the internal <BR> // secret value, and generate a string that can be used to verify <BR> // that the remote user is known to us. The result of this function <BR> // is a single string, that can be passed along in a hidden form <BR> // or even a cookie. <BR> // <BR> // If ($time) is 0, the current time is used instead. <BR> // <BR> // ($identity) _cannot_ contain a ``:'' character. If you need <BR> // one in there, you will have to change it to some sort of escape <BR> // sequence. <BR> // <BR> // Some care should be used. I recommend using this only over SSL, <BR> // unless the actual ticket contents are encrypted using something <BR> // stronger than XOR. <BR> // <BR> function makeauth($identity, $time) <BR> { <BR> global $REMOTE_ADDR; <BR> $this->zerodata(); <BR> if ($time == 0) <BR> $time = time(); <BR> $ticket_items[] = (string)$time; <BR> $ticket_items[] = $this->realm; <BR> $ticket_items[] = $REMOTE_ADDR; <BR> $ticket_items[] = $identity; <BR> $ticket = implode($ticket_items, ":"); <BR> $hash = md5($this->secret . $ticket); <BR> $ticket = $hash . ':' . $ticket; <BR> $this->identity = $identity; <BR> $this->issue = $time; <BR> $this->remote_addr = $REMOTE_ADDR; <BR> $this->hash = $hash; <BR> $this->authenticated = 1; /* data is valid */ <BR> $this->autherr = ""; <BR> return $ticket; <BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -