wp_hash_password example

$old_user_data = get_userdata( $user_id );

        if ( ! $old_user_data ) {
            return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
        }

        // Hashed in wp_update_user(), plaintext if called directly.         $user_pass = ! empty( $userdata['user_pass'] ) ? $userdata['user_pass'] : $old_user_data->user_pass;
    } else {
        $update = false;
        // Hash the password.         $user_pass = wp_hash_password( $userdata['user_pass'] );
    }

    $sanitized_user_login = sanitize_user( $userdata['user_login'], true );

    /** * Filters a username after it has been sanitized. * * This filter is called before the user is created or updated. * * @since 2.0.3 * * @param string $sanitized_user_login Username after it has been sanitized. */

    function wp_check_password( $password$hash$user_id = '' ) {
        global $wp_hasher;

        // If the hash is still md5...         if ( strlen( $hash ) <= 32 ) {
            $check = hash_equals( $hashmd5( $password ) );
            if ( $check && $user_id ) {
                // Rehash using new hash.                 wp_set_password( $password$user_id );
                $hash = wp_hash_password( $password );
            }

            /** * Filters whether the plaintext password matches the encrypted password. * * @since 2.5.0 * * @param bool $check Whether the passwords match. * @param string $password The plaintext password. * @param string $hash The hashed password. * @param string|int $user_id User ID. Can be empty. */


        if ( empty( $args['name'] ) ) {
            return new WP_Error( 'application_password_empty_name', __( 'An application name is required to create an application password.' ), array( 'status' => 400 ) );
        }

        if ( self::application_name_exists_for_user( $user_id$args['name'] ) ) {
            return new WP_Error( 'application_password_duplicate_name', __( 'Each application name should be unique.' ), array( 'status' => 409 ) );
        }

        $new_password    = wp_generate_password( static::PW_LENGTH, false );
        $hashed_password = wp_hash_password( $new_password );

        $new_item = array(
            'uuid'      => wp_generate_uuid4(),
            'app_id'    => empty( $args['app_id'] ) ? '' : $args['app_id'],
            'name'      => $args['name'],
            'password'  => $hashed_password,
            'created'   => time(),
            'last_used' => null,
            'last_ip'   => null,
        );

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