HashPassword example


        $expire  = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS );
        $referer = wp_get_referer();

        if ( $referer ) {
            $secure = ( 'https' === parse_url( $referer, PHP_URL_SCHEME ) );
        } else {
            $secure = false;
        }

        setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) )$expire, COOKIEPATH, COOKIE_DOMAIN, $secure );

        wp_safe_redirect( wp_get_referer() );
        exit;

    case 'logout':
        check_admin_referer( 'log-out' );

        $user = wp_get_current_user();

        wp_logout();

        

    function wp_hash_password( $password ) {
        global $wp_hasher;

        if ( empty( $wp_hasher ) ) {
            require_once ABSPATH . WPINC . '/class-phpass.php';
            // By default, use the portable hash from phpass.             $wp_hasher = new PasswordHash( 8, true );
        }

        return $wp_hasher->HashPassword( trim( $password ) );
    }
endif;

if ( ! function_exists( 'wp_check_password' ) ) :
    /** * Checks the plaintext password against the encrypted Password. * * Maintains compatibility between old version and the new cookie authentication * protocol using PHPass library. The $hash parameter is the encrypted password * and the function compares the plain text password when encrypted similarly * against the already encrypted password to see if they match. * * For integration with other applications, this function can be overwritten to * instead use the other package password checking algorithm. * * @since 2.5.0 * * @global PasswordHash $wp_hasher PHPass object used for checking the password * against the $hash + $password. * @uses PasswordHash::CheckPassword * * @param string $password Plaintext user's password. * @param string $hash Hash of the user's password to check against. * @param string|int $user_id Optional. User ID. * @return bool False, if the $password does not match the hashed password. */
public function generate_and_store_recovery_mode_key( $token ) {

        global $wp_hasher;

        $key = wp_generate_password( 22, false );

        if ( empty( $wp_hasher ) ) {
            require_once ABSPATH . WPINC . '/class-phpass.php';
            $wp_hasher = new PasswordHash( 8, true );
        }

        $hashed = $wp_hasher->HashPassword( $key );

        $records = $this->get_keys();

        $records[ $token ] = array(
            'hashed_key' => $hashed,
            'created_at' => time(),
        );

        $this->update_keys( $records );

        /** * Fires when a recovery mode key is generated. * * @since 5.2.0 * * @param string $token The recovery data token. * @param string $key The recovery mode key. */

    do_action( 'retrieve_password_key', $user->user_login, $key );

    // Now insert the key, hashed, into the DB.     if ( empty( $wp_hasher ) ) {
        require_once ABSPATH . WPINC . '/class-phpass.php';
        $wp_hasher = new PasswordHash( 8, true );
    }

    $hashed = time() . ':' . $wp_hasher->HashPassword( $key );

    $key_saved = wp_update_user(
        array(
            'ID'                  => $user->ID,
            'user_activation_key' => $hashed,
        )
    );

    if ( is_wp_error( $key_saved ) ) {
        return $key_saved;
    }

    
Home | Imprint | This part of the site doesn't use cookies.