Last active
July 27, 2020 04:32
-
-
Save chwnam/4c0ff266fa4fad6315d3f3a28a33b2ae to your computer and use it in GitHub Desktop.
워드프레스 로그인 스터디
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: 워드프레스 로그인 스터디 | |
| * Description: WordPress Core #3 용 데모 플러그인 | |
| */ | |
| function phs_dump_obj( $obj, $title = '' ) { | |
| if ( $title ) { | |
| echo '<h3>' . esc_html( $title ) . '</h3>'; | |
| } | |
| echo '<p><pre>' . print_r( $obj, 1 ) . '</pre></p>'; | |
| } | |
| add_action( 'admin_menu', function () { | |
| add_menu_page( | |
| 'Password Hash', | |
| 'Password Hash', | |
| 'administrator', | |
| 'password-hash', | |
| function () { | |
| $input = sanitize_text_field( $_GET['pwd-input'] ?? '' ); | |
| $crypt = $input ? wp_hash_password( $input ) : ''; | |
| $vector = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; | |
| ?> | |
| <div class="wrap"> | |
| <h1 class="wp-heading-inline">Hassword Hash Study</h1> | |
| <hr class="wp-header-end"> | |
| <style> | |
| .label { | |
| display: inline-block; | |
| min-width: 120px; | |
| font-weight: 600; | |
| } | |
| </style> | |
| <form action="" method="get"> | |
| <table class="form-table"> | |
| <tr> | |
| <th scope="row"> | |
| <label class="label" for="pwd-input">문자열 입력</label> | |
| </th> | |
| <td> | |
| <input id="pwd-input" name="pwd-input" value="<?php echo esc_attr( $input ); ?>"> | |
| </td> | |
| </tr> | |
| <?php if ( $crypt ) : ?> | |
| <tr> | |
| <th scope="row"> | |
| 결과 | |
| </th> | |
| <td> | |
| <?php echo esc_html( $crypt ); ?> | |
| </td> | |
| </tr> | |
| <tr> | |
| <th scope="row"> | |
| 해시 알고리즘 코드 | |
| </th> | |
| <td> | |
| <?php echo esc_html( substr( $crypt, 0, 3 ) ); ?> | |
| </td> | |
| </tr> | |
| <tr> | |
| <th scope="row"> | |
| 반복 수 | |
| </th> | |
| <td> | |
| <?php echo esc_html( $crypt[3] ); ?> | |
| <?php echo '(' . intval( strpos( $vector, $crypt[3] ) ) . ')'; ?> | |
| </td> | |
| </tr> | |
| <tr> | |
| <th scope="row"> | |
| 솔트 | |
| </th> | |
| <td> | |
| <?php echo esc_html( substr( $crypt, 4, 8 ) ); ?> | |
| </td> | |
| </tr> | |
| <tr> | |
| <th scope="row"> | |
| 해시 | |
| </th> | |
| <td> | |
| <?php echo esc_html( substr( $crypt, 12 ) ) . ' (' . strlen( substr( $crypt, 12 ) ) . '글자)'; ?> | |
| </td> | |
| </tr> | |
| <?php endif; ?> | |
| </table> | |
| <input type="hidden" name="page" value="<?php echo esc_attr( $_GET['page'] ); ?>"> | |
| <?php submit_button( '제출' ); ?> | |
| </form> | |
| <?php if ( $crypt ) : ?> | |
| <h2>해시 비교</h2> | |
| <?php | |
| $salt = substr( $crypt, 4, 8 ); | |
| $count = 1 << 13; | |
| $raw_hash = md5( $salt . $input, true ); | |
| do { | |
| $raw_hash = md5( $raw_hash . $input, true ); | |
| } while ( -- $count ); | |
| ?> | |
| <table class="form-table"> | |
| <tr> | |
| <th scope="row"> | |
| 2진수 6비트 | |
| </th> | |
| <td> | |
| <?php | |
| $hash = substr( $crypt, 12 ); | |
| $six_bits = []; | |
| for ( $i = 0; $i < strlen( $hash ); ++ $i ) { | |
| $six_bits[] = sprintf( '%06d', decbin( strpos( $vector, $hash[ $i ] ) ) ); | |
| } | |
| ?> | |
| <pre><?= $six_bits[3] ?> - <?= $six_bits[2] ?> - <?= $six_bits[1] ?> - <?= $six_bits[0] ?> (<?= $hash[3] ?> - <?= $hash[2] ?> - <?= $hash[1] ?> - <?= $hash[0] ?> )</pre> | |
| <pre><?= $six_bits[7] ?> - <?= $six_bits[6] ?> - <?= $six_bits[5] ?> - <?= $six_bits[4] ?> (<?= $hash[7] ?> - <?= $hash[6] ?> - <?= $hash[5] ?> - <?= $hash[4] ?> )</pre> | |
| <pre><?= $six_bits[11] ?> - <?= $six_bits[10] ?> - <?= $six_bits[8] ?> - <?= $six_bits[8] ?> (<?= $hash[11] ?> - <?= $hash[10] ?> - <?= $hash[9] ?> - <?= $hash[8] ?> )</pre> | |
| <pre><?= $six_bits[15] ?> - <?= $six_bits[14] ?> - <?= $six_bits[13] ?> - <?= $six_bits[12] ?> (<?= $hash[15] ?> - <?= $hash[14] ?> - <?= $hash[13] ?> - <?= $hash[12] ?> )</pre> | |
| <pre><?= $six_bits[19] ?> - <?= $six_bits[18] ?> - <?= $six_bits[17] ?> - <?= $six_bits[16] ?> (<?= $hash[19] ?> - <?= $hash[18] ?> - <?= $hash[17] ?> - <?= $hash[16] ?> )</pre> | |
| <pre><?= $six_bits[21] ?> - <?= $six_bits[20] ?> (<?= $hash[21] ?> - <?= $hash[20] ?> )</pre> | |
| </td> | |
| </tr> | |
| <tr> | |
| <th scope="row"> | |
| 2진수 8비트 | |
| </th> | |
| <td> | |
| <?php | |
| $eight_bits = [ | |
| $six_bits[3] . substr( $six_bits[2], 0, 2 ), | |
| substr( $six_bits[2], 2 ) . substr( $six_bits[1], 0, 4 ), | |
| substr( $six_bits[1], 4 ) . $six_bits[0], | |
| $six_bits[7] . substr( $six_bits[6], 0, 2 ), | |
| substr( $six_bits[6], 2 ) . substr( $six_bits[5], 0, 4 ), | |
| substr( $six_bits[5], 4 ) . $six_bits[4], | |
| $six_bits[11] . substr( $six_bits[10], 0, 2 ), | |
| substr( $six_bits[10], 2 ) . substr( $six_bits[9], 0, 4 ), | |
| substr( $six_bits[9], 4 ) . $six_bits[8], | |
| $six_bits[15] . substr( $six_bits[14], 0, 2 ), | |
| substr( $six_bits[14], 2 ) . substr( $six_bits[13], 0, 4 ), | |
| substr( $six_bits[13], 4 ) . $six_bits[12], | |
| $six_bits[19] . substr( $six_bits[18], 0, 2 ), | |
| substr( $six_bits[18], 2 ) . substr( $six_bits[17], 0, 4 ), | |
| substr( $six_bits[17], 4 ) . $six_bits[16], | |
| substr( $six_bits[21], 4 ) . $six_bits[20], | |
| ]; | |
| ?> | |
| <pre><?= $eight_bits[0] ?> - <?= $eight_bits[1] ?> - <?= $eight_bits[2] ?> (<?= dechex( intval( $eight_bits[0], 2 ) ) ?> - <?= dechex( intval( $eight_bits[1], 2 ) ) ?> - <?= dechex( intval( $eight_bits[2], 2 ) ) ?>)</pre> | |
| <pre><?= $eight_bits[3] ?> - <?= $eight_bits[4] ?> - <?= $eight_bits[5] ?> (<?= dechex( intval( $eight_bits[3], 2 ) ) ?> - <?= dechex( intval( $eight_bits[4], 2 ) ) ?> - <?= dechex( intval( $eight_bits[5], 2 ) ) ?>)</pre> | |
| <pre><?= $eight_bits[6] ?> - <?= $eight_bits[7] ?> - <?= $eight_bits[8] ?> (<?= dechex( intval( $eight_bits[6], 2 ) ) ?> - <?= dechex( intval( $eight_bits[7], 2 ) ) ?> - <?= dechex( intval( $eight_bits[8], 2 ) ) ?>)</pre> | |
| <pre><?= $eight_bits[9] ?> - <?= $eight_bits[10] ?> - <?= $eight_bits[11] ?> (<?= dechex( intval( $eight_bits[9], 2 ) ) ?> - <?= dechex( intval( $eight_bits[10], 2 ) ) ?> - <?= dechex( intval( $eight_bits[11], 2 ) ) ?>)</pre> | |
| <pre><?= $eight_bits[12] ?> - <?= $eight_bits[13] ?> - <?= $eight_bits[14] ?> (<?= dechex( intval( $eight_bits[12], 2 ) ) ?> - <?= dechex( intval( $eight_bits[13], 2 ) ) ?> - <?= dechex( intval( $eight_bits[14], 2 ) ) ?>)</pre> | |
| <pre><?= $eight_bits[15] ?> (<?= dechex( intval( $eight_bits[15], 2 ) ) ?>)</pre> | |
| </td> | |
| </tr> | |
| <tr> | |
| <th scope="row"> | |
| 직접 계산한 해시 | |
| </th> | |
| <td> | |
| <?php | |
| $raw_hash_hex = []; | |
| for ( $i = 0; $i < strlen( $raw_hash ); ++ $i ) { | |
| $hex = dechex( ord( $raw_hash[ $i ] ) ); | |
| $raw_hash_hex[] = 2 == strlen( $hex ) ? $hex : '0' . $hex; | |
| } | |
| ?> | |
| <pre><?php echo implode( ' ', $raw_hash_hex ); ?></pre> | |
| </td> | |
| </tr> | |
| </table> | |
| <?php endif; ?> | |
| <br class="clear"> | |
| </div> | |
| <?php | |
| } | |
| ); | |
| } ); | |
| //add_action( 'init', function () { | |
| // global $wp_hasher; | |
| // | |
| // require_once ABSPATH . WPINC . '/class-phpass.php'; | |
| // | |
| // $wp_hasher = new PasswordHash( 8, false ); | |
| //}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment