Browse Source

generate_tripcode() rewrite

pull/40/head
Savetheinternet 13 years ago
parent
commit
95920a6972
  1. 61
      inc/functions.php

61
inc/functions.php

@ -1384,42 +1384,39 @@
return substr(sha1(sha1($ip . $config['secure_trip_salt'] . $thread) . $config['secure_trip_salt']), 0, $config['poster_id_length']); return substr(sha1(sha1($ip . $config['secure_trip_salt'] . $thread) . $config['secure_trip_salt']), 0, $config['poster_id_length']);
} }
function generate_tripcode($name, $length = 10){ function generate_tripcode($name) {
global $config; global $config;
$t = explode('#', $name);
$nameo = $t[0]; if(!preg_match('/^([^#]+)?(##|#)(.+)$/', $name, $match))
if ( isset ( $t[1] ) || isset ( $t[2] ) ) { return Array($name);
$trip = ( ( strlen ( $t[1] ) > 0 ) ? $t[1] : $t[2] );
if ( ( function_exists ( 'mb_convert_encoding' ) ) ) { $name = $match[1];
// multi-byte encoding is necessary to produce standard tripcode output, but only use it if available $secure = $match[2] == '##';
mb_substitute_character('none'); $trip = $match[3];
$recoded_cap = mb_convert_encoding ( $trip, 'Shift_JIS', 'UTF-8' );
} // convert to SHIT_JIS encoding
$trip = ( ( ! empty ( $recoded_cap ) ) ? $recoded_cap : $trip ); $trip = mb_convert_encoding($trip, 'Shift_JIS', 'UTF-8');
$salt = substr ( $trip.'H.', 1, 2 );
$salt = preg_replace ( '/[^\.-z]/', '.', $salt ); // generate salt
$salt = strtr ( $salt, ':;<=>?@[\]^_`', 'ABCDEFGabcdef' ); $salt = substr($trip . 'H..', 1, 2);
if ( isset ( $t[2] ) ) { $salt = preg_replace('/[^\.-z]/', '.', $salt);
// secure $salt = strtr($salt, ':;<=>?@[\]^_`', 'ABCDEFGabcdef');
if(isset($config['custom_tripcode']["##{$trip}"]))
$trip = $config['custom_tripcode']["##{$trip}"]; if($secure) {
else if(isset($config['custom_tripcode']["##{$trip}"]))
$trip = '!!' . substr ( crypt ( $trip, $config['secure_trip_salt'] ), ( -1 * $length ) ); $trip = $config['custom_tripcode']["##{$trip}"];
} else { else
// insecure $trip = '!!' . substr(crypt($trip, $config['secure_trip_salt']), -10);
if(isset($config['custom_tripcode']["#{$trip}"]))
$trip = $config['custom_tripcode']["#{$trip}"];
else
$trip = '!' . substr ( crypt ( $trip, $salt ), ( -1 * $length ) );
}
}
if ( isset ( $trip ) ) {
return array ( $nameo, $trip );
} else { } else {
return array ( $nameo ); if(isset($config['custom_tripcode']["#{$trip}"]))
$trip = $config['custom_tripcode']["#{$trip}"];
else
$trip = '!' . substr(crypt($trip, $salt), -10);
} }
return Array($name, $trip);
} }
// Highest common factor // Highest common factor
function hcf($a, $b){ function hcf($a, $b){
$gcd = 1; $gcd = 1;

Loading…
Cancel
Save