Mantis只在cookie中的设置一个MANTIS_STRING_COOKIE
这是个64位长的唯一值。那么它是怎么得到的呢?
我们在authentication_api.php中得到三个函数:
function auth_generate_cookie_string() {
$t_val = mt_rand( 0, mt_getrandmax() ) + mt_rand( 0, mt_getrandmax() );
$t_val = md5( $t_val ) . md5( time() );return substr( $t_val, 0, 64 );
}# ——————–
# Generate a UNIQUE string to use as the identifier for the login cookie
# The string returned should be 64 characters in length
function auth_generate_unique_cookie_string() {
do {
$t_cookie_string = auth_generate_cookie_string();
} while ( !auth_is_cookie_string_unique( $t_cookie_string ) );
return $t_cookie_string;
}# ——————–
# Return true if the cookie login identifier is unique, false otherwise
function auth_is_cookie_string_unique( $p_cookie_string ) {
$t_user_table = config_get( ‘mantis_user_table’ );$c_cookie_string = db_prepare_string( $p_cookie_string );
$query = “SELECT COUNT(*)
FROM $t_user_table
WHERE cookie_string=’$c_cookie_string’”;
$result = db_query( $query );
$t_count = db_result( $result );if ( $t_count > 0 ) {
return false;
} else {
return true;
}
}
不复杂的函数,很容易的看懂。
而在ot中,我将之加入了第一个函数,并作出修改。因为email的唯一性,我设置如下
/**
* 取得64位唯一值
*
*/
function auth_generate_cookie_string( $email ) {
$t_val = mt_rand( 0, mt_getrandmax() ) + mt_rand( 0, mt_getrandmax() );
$t_val = md5( $t_val ) . md5( time() ). md5($email);return substr( $t_val, 0, 64 );
}
我想就不需要轮换来取绝对值了。重复的可能性极小了。
Leave a Reply
You must be logged in to post a comment.

Recent Comments