Browse Source

generate_tripcode() rewrite

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

47
inc/functions.php

@ -1384,40 +1384,37 @@
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($secure) {
if(isset($config['custom_tripcode']["##{$trip}"])) if(isset($config['custom_tripcode']["##{$trip}"]))
$trip = $config['custom_tripcode']["##{$trip}"]; $trip = $config['custom_tripcode']["##{$trip}"];
else else
$trip = '!!' . substr ( crypt ( $trip, $config['secure_trip_salt'] ), ( -1 * $length ) ); $trip = '!!' . substr(crypt($trip, $config['secure_trip_salt']), -10);
} else { } else {
// insecure
if(isset($config['custom_tripcode']["#{$trip}"])) if(isset($config['custom_tripcode']["#{$trip}"]))
$trip = $config['custom_tripcode']["#{$trip}"]; $trip = $config['custom_tripcode']["#{$trip}"];
else else
$trip = '!' . substr ( crypt ( $trip, $salt ), ( -1 * $length ) ); $trip = '!' . substr(crypt($trip, $salt), -10);
}
}
if ( isset ( $trip ) ) {
return array ( $nameo, $trip );
} else {
return array ( $nameo );
} }
return Array($name, $trip);
} }
// Highest common factor // Highest common factor

Loading…
Cancel
Save