Changeset 1832
- Timestamp:
- 12/08/2008 07:18:40 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
bb-admin/includes/class.bb-install.php (modified) (3 diffs)
-
bb-admin/install.php (modified) (1 diff)
-
bb-config-sample.php (modified) (1 diff)
-
bb-includes/functions.bb-pluggable.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bb-admin/includes/class.bb-install.php
r1804 r1832 678 678 'prerequisite' => 'toggle_1' 679 679 ), 680 'bb_nonce_key' => array( 681 'value' => $_bb_default_secret_key, 682 'label' => __('bbPress "nonce" key'), 683 'note' => __('This should be a unique and secret phrase, it will be used to make form submission harder for an attacker to spoof.'), 684 'prerequisite' => 'toggle_1' 685 ), 680 686 'bb_table_prefix' => array( 681 687 'value' => 'bb_', … … 1174 1180 $data['bb_secure_auth_key']['value'] = addslashes(stripslashes($data['bb_secure_auth_key']['value'])); 1175 1181 $data['bb_logged_in_key']['value'] = addslashes(stripslashes($data['bb_logged_in_key']['value'])); 1182 $data['bb_nonce_key']['value'] = addslashes(stripslashes($data['bb_nonce_key']['value'])); 1176 1183 } 1177 1184 … … 1224 1231 "define('BB_SECURE_AU" => array("'put your unique phrase here'", "'" . $data['bb_secure_auth_key']['value'] . "'"), 1225 1232 "define('BB_LOGGED_IN" => array("'put your unique phrase here'", "'" . $data['bb_logged_in_key']['value'] . "'"), 1233 "define('BB_NONCE_KEY" => array("'put your unique phrase here'", "'" . $data['bb_nonce_key']['value'] . "'"), 1226 1234 "\$bb_table_prefix = '" => array("'bb_'", "'" . $data['bb_table_prefix']['value'] . "'"), 1227 1235 "define('BB_LANG', ''" => array("''", "'" . $data['bb_lang']['value'] . "'") -
trunk/bb-admin/install.php
r1802 r1832 68 68 $bb_install->input_text('bb_secure_auth_key'); 69 69 $bb_install->input_text('bb_logged_in_key'); 70 $bb_install->input_text('bb_nonce_key'); 70 71 $bb_install->input_text('bb_table_prefix', 'ltr'); 71 72 ?> -
trunk/bb-config-sample.php
r1809 r1832 19 19 define('BB_SECURE_AUTH_KEY', 'put your unique phrase here'); // Change this to a unique phrase. 20 20 define('BB_LOGGED_IN_KEY', 'put your unique phrase here'); // Change this to a unique phrase. 21 define('BB_NONCE_KEY', 'put your unique phrase here'); // Change this to a unique phrase. 21 22 22 23 // If you are running multiple bbPress installations in a single database, -
trunk/bb-includes/functions.bb-pluggable.php
r1807 r1832 272 272 endif; 273 273 274 if ( !function_exists('wp_nonce_tick') ) : 275 /** 276 * Get the time-dependent variable for nonce creation. 277 * 278 * A nonce has a lifespan of two ticks. Nonces in their second tick may be 279 * updated, e.g. by autosave. 280 * 281 * @since 1.0 282 * 283 * @return int 284 */ 285 function bb_nonce_tick() { 286 $nonce_life = apply_filters('bb_nonce_life', 86400); 287 288 return ceil(time() / ( $nonce_life / 2 )); 289 } 290 endif; 291 274 292 if ( !function_exists('bb_verify_nonce') ) : 293 /** 294 * Verify that correct nonce was used with time limit. 295 * 296 * The user is given an amount of time to use the token, so therefore, since the 297 * UID and $action remain the same, the independent variable is the time. 298 * 299 * @param string $nonce Nonce that was used in the form to verify 300 * @param string|int $action Should give context to what is taking place and be the same when nonce was created. 301 * @return bool Whether the nonce check passed or failed. 302 */ 275 303 function bb_verify_nonce($nonce, $action = -1) { 276 304 $user = bb_get_current_user(); 277 $uid = $user->ID;278 279 $i = ceil(time() / 43200);305 $uid = (int) $user->ID; 306 307 $i = bb_nonce_tick(); 280 308 281 309 // Nonce generated 0-12 hours ago 282 if ( substr(wp_hash($i . $action . $uid ), -12, 10) == $nonce )310 if ( substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) == $nonce ) 283 311 return 1; 284 312 // Nonce generated 12-24 hours ago 285 if ( substr(wp_hash(($i - 1) . $action . $uid ), -12, 10) == $nonce )313 if ( substr(wp_hash(($i - 1) . $action . $uid, 'nonce'), -12, 10) == $nonce ) 286 314 return 2; 287 315 // Invalid nonce … … 291 319 292 320 if ( !function_exists('bb_create_nonce') ) : 321 /** 322 * Creates a random, one time use token. 323 * 324 * @since 2.0.4 325 * 326 * @param string|int $action Scalar value to add context to the nonce. 327 * @return string The one use form token 328 */ 293 329 function bb_create_nonce($action = -1) { 294 330 $user = bb_get_current_user(); 295 $uid = $user->ID; 296 297 $i = ceil(time() / 43200); 298 299 return substr(wp_hash($i . $action . $uid), -12, 10); 300 } 301 endif; 302 303 // Not verbatim WP, constants have different names. 331 $uid = (int) $user->ID; 332 333 $i = bb_nonce_tick(); 334 335 return substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10); 336 } 337 endif; 338 339 function _bb_get_key( $key, $default_key = false ) { 340 if ( !$default_key ) { 341 global $bb_default_secret_key; 342 $default_key = $bb_default_secret_key; 343 } 344 345 if ( defined( $key ) && '' != constant( $key ) && $default_key != constant( $key ) ) { 346 return $key; 347 } 348 349 return $default_key; 350 } 351 352 function _bb_get_salt( $constants, $option = false ) { 353 if ( !is_array( $constants ) ) { 354 $constants = array( $constants ); 355 } 356 357 foreach ($constants as $constant ) { 358 if ( defined( $constant ) ) { 359 return constant( $constant ); 360 } 361 } 362 363 if ( !defined( 'BB_INSTALLING' ) || !BB_INSTALLING ) { 364 if ( !$option ) { 365 $option = strtolower( $constants[0] ); 366 } 367 $salt = bb_get_option( $option ); 368 if ( empty( $salt ) ) { 369 $salt = wp_generate_password(); 370 bb_update_option( $option, $salt ); 371 } 372 return $salt; 373 } 374 375 return ''; 376 } 377 378 // Not verbatim WP, constants have different names, uses helper functions. 304 379 if ( !function_exists('wp_salt') ) : 305 380 function wp_salt($scheme = 'auth') { 306 global $bb_default_secret_key; 307 308 $secret_key = ''; 309 if ( defined('BB_SECRET_KEY') && ('' != BB_SECRET_KEY) && ($bb_default_secret_key != BB_SECRET_KEY) ) 310 $secret_key = BB_SECRET_KEY; 311 381 $secret_key = _bb_get_key( 'BB_SECRET_KEY' ); 382 312 383 switch ($scheme) { 313 384 case 'auth': 314 if ( defined('BB_AUTH_KEY') && ('' != BB_AUTH_KEY) && ( $bb_default_secret_key != BB_AUTH_KEY) ) 315 $secret_key = BB_AUTH_KEY; 316 317 if ( defined('BB_AUTH_SALT') ) { 318 $salt = BB_AUTH_SALT; 319 } elseif ( defined('BB_SECRET_SALT') ) { 320 $salt = BB_SECRET_SALT; 321 } elseif ( !BB_INSTALLING ) { 322 $salt = bb_get_option('bb_auth_salt'); 323 if ( empty($salt) ) { 324 $salt = wp_generate_password(); 325 bb_update_option('bb_auth_salt', $salt); 326 } 327 } 385 $secret_key = _bb_get_key( 'BB_AUTH_KEY', $secret_key ); 386 $salt = _bb_get_salt( array( 'BB_AUTH_SALT', 'BB_SECRET_SALT' ) ); 328 387 break; 329 388 330 389 case 'secure_auth': 331 if ( defined('BB_SECURE_AUTH_KEY') && ('' != BB_SECURE_AUTH_KEY) && ( $bb_default_secret_key != BB_SECURE_AUTH_KEY) ) 332 $secret_key = BB_SECURE_AUTH_KEY; 333 334 if ( defined('BB_SECURE_AUTH_SALT') ) { 335 $salt = BB_SECURE_AUTH_SALT; 336 } else { 337 $salt = bb_get_option('bb_secure_auth_salt'); 338 if ( empty($salt) ) { 339 $salt = wp_generate_password(); 340 bb_update_option('bb_secure_auth_salt', $salt); 341 } 342 } 390 $secret_key = _bb_get_key( 'BB_SECURE_AUTH_KEY', $secret_key ); 391 $salt = _bb_get_salt( 'BB_SECURE_AUTH_SALT' ); 343 392 break; 344 393 345 394 case 'logged_in': 346 if ( defined('BB_LOGGED_IN_KEY') && ('' != BB_LOGGED_IN_KEY) && ( $bb_default_secret_key != BB_LOGGED_IN_KEY) ) 347 $secret_key = BB_LOGGED_IN_KEY; 348 349 if ( defined('BB_LOGGED_IN_SALT') ) { 350 $salt = BB_LOGGED_IN_SALT; 351 } else { 352 $salt = bb_get_option('bb_logged_in_salt'); 353 if ( empty($salt) && ( !defined( 'BB_INSTALLING' ) || !BB_INSTALLING ) ) { 354 $salt = wp_generate_password(); 355 bb_update_option('bb_logged_in_salt', $salt); 356 } 357 } 395 $secret_key = _bb_get_key( 'BB_LOGGED_IN_KEY', $secret_key ); 396 $salt = _bb_get_salt( 'BB_LOGGED_IN_SALT' ); 358 397 break; 359 } 360 361 return apply_filters('salt', $secret_key . $salt, $scheme); 398 399 case 'nonce': 400 $secret_key = _bb_get_key( 'BB_NONCE_KEY', $secret_key ); 401 $salt = _bb_get_salt( 'BB_NONCE_SALT' ); 402 break; 403 404 default: 405 // ensure each auth scheme has its own unique salt 406 $salt = hash_hmac( 'md5', $scheme, $secret_key ); 407 break; 408 } 409 410 return apply_filters( 'salt', $secret_key . $salt, $scheme ); 362 411 } 363 412 endif;
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)