Windows 10 Logo

How to Reset Your Windows 10 Password

I have pieced together several guides to come up with a reliable method of resetting a Windows 7, 8 or 10 password. I’m not sure if it will work for user accounts tied to a Windows Live account on Windows 10 though. The below video by Nehal J Wani on YouTube forms the core of this solution. You should only need to use this method if you do not have a copy of Windows, or a Password Recovery Disk.

Download UNetbootin. This application creates bootable Linux Distributions. It is cross platform but my guide will focus on creating the Live USB using Mac. Bring up the context menu in Finder and select Open. Enter your password to let Mac open the application.

Unfortunately the Distribution is not listed as a download in this application. So you’ll want to download SystemRescueCd ISO as suggested by the YouTube video. It should be easy enough for you to use UNetbootin to create a bootable USB from the downloaded ISO. If you are unsure which drive is your USB, enter diskutil list in the Terminal.

Reboot the problem computer and boot from the USB. Some BIOS will complain about the USB breaching a security policy. You’ll need to enter BIOS and disable the UEFI security. This will vary based on your BIOS version. It is usually pretty obvious and listed under Boot or Security.

Once you are able to boot from the USB. Select the first option and follow the prompts until you reach the Terminal. Type gdisk -l /dev/sda to find your Windows partition. The largest partition on your main drive is usually the safe bet.

You can try to mount the Windows partition using mount /dev/sda? /mnt (replace ? with the partition number). If you get an error message about the NTFS partition being hibernated you can try mount -t ntfs-3g -o remove_hiberfile /dev/sda? /mnt as an alternative.

Now we can perform the steps as demonstrated in the video:

  1. cd /mnt/Windows/System32/Config
  2. chntpw -i SAM
  3. Press 1
  4. Enter the RID of the user you wish to change the password for.
  5. Press 1
  6. Press q
  7. Press q
  8. Press y
  9. cd
  10. umount /mnt
  11. reboot

While the computer reboots, unplug the USB. Your user account should now login without any need for a password. Once logged in, you can go into your user account and reset your password from within Windows.

There are several other methods of resetting a Windows password. It really comes down to what you have available. I believe the Offline Windows Password & Registry Editor uses a very similar process. There is also the Sticky Keys trick, but that only works if Sticky Keys are enabled prior to being locked out.

jQuery Logo

jQuery Smooth Scroll to Anchor

Have you ever wanted to smoothly scroll to an anchor on a page with jQuery? The script example I have provided allows several functionalities. If you enter a page with an anchor hash directly, it will smooth scroll to that point on the page. It will also update the hash, and calculate the height of a sticky header or menu.

This works best as an inline script, but does also work when placed inside a JavaScript file.

/**
 * jQuery Smooth Scroll to Anchor
 */
var pauseHashOnChange = false;

// Initialises the Smooth Scroll Functionality
function initSmoothScroll( e, ele ) 
{    
    e.preventDefault();
    url = jQuery( ele ).prop('href');
    hash = url.substring( url.indexOf('#') + 1 );
    hashChange( hash );
}

// Hash Change
function hashChange( hash )
{
    hash = hash ? hash : window.location.hash.slice(1);
    ele = 'a[name=' + hash + ']';

    if ( hash && jQuery( ele ).hasClass('smooth-scroll-target') )
    {
        jQuery( ele ).trigger('click');
        smoothScroll( ele );
    }    
}

// Smooth Scroll
function smoothScroll( ele )
{
    ele = jQuery(ele);
    extraOffset = 30;
    headerOffset = jQuery('header').height();
    offset = headerOffset - extraOffset;

    jQuery('html, body').stop().animate({
        'scrollTop' : ele.offset().top - offset
    }, 900, 'swing', function() {
        pauseHashOnChange = true;
        window.location.hash = ele.prop('name');
        pauseHashOnChange = false;
    });
}

// Run Hash Change onload to trigger the click event and then scroll to the anchor.
jQuery(window).load( function() {
    hashChange();
});

jQuery(document).ready( function($) {
    
    // Listen for Hash Change events.
    $(window).on('hashchange', function() { 
        if ( !pauseHashOnChange )
            hashChange();
    });
    
    // Attach the Smooth Scroll event to a class.
    $('.smooth-scroll').click( function( e ) {
        initSmoothScroll( e, this );
    });
});
<a href="#anchor" class="smooth-scroll">Smooth Scroll</a>
<a name="anchor" class="smooth-scroll-target"></a>
WordPress Logo

Convert Taxonomy Options to Term Meta

WordPress 4.4 introduced Taxonomy Term Meta. Until this version, meta had to be stored as an Option. Most tutorials would tell you to give it a prefix followed by the ‘term_id’ so you can grab the data easily later. I already had a site with lots of populated meta. What I needed was a conversion script to move meta from an Option into real Term Meta.

/**
 * Convert Taxonomy Options to Term Meta
 */
$taxonomy = 'my_taxonomy';
$option_prefix = 'taxonomy_';

$taxonomy_terms = get_terms( $taxonomy, array( 'hide_empty' => false ) );
$counter = 0;

foreach ( $taxonomy_terms as $term )
{
    $term_id = $term->term_id;
    $option = get_option( $option_prefix . $term_id );

    if ( !empty( $option ) )
    {
        $counter++;

        foreach ( $option as $meta_key => $meta_value )
        {
            delete_term_meta( $term_id, $meta_key );

            if ( !empty( $meta_value ) )
                update_term_meta( $term_id, $meta_key, $meta_value, true );
        }
    }
}

echo "Processed " . $counter . " Taxonomy Term Options";

$counter = 0;

foreach ( $taxonomy_terms as $term )
{
    $term_meta = get_term_meta( $term->term_id );

    if ( !empty( $term_meta ) )
        $counter++;
}

echo " >> [ " . $counter . " ] Taxonomy Terms now have Term Meta.";

I found a couple of interesting quirks with Term Meta while converting my site.

The first is that if you run get_term_meta( $term->term_id ) it will present you with an array of arrays. The value is stored as the first key of these sub-arrays. Where you might have had $term_meta[‘my_key’] for your option, you now need $term_meta[‘my_key’][0]. If the value returned is an array, it will need to be unserialized. This only applies if you want all Term Meta for a taxonomy. If you use get_term_meta( $term->term_id, ‘my_key’, true ) it will automatically perform both these tasks to return a single meta key.

Another difference shows itself when saving values. An Option will overwrite the value (array) in most cases. However the update function for Term Meta will only update individual meta keys. You need to iterate through and store them individually. However this is no bueno when using checkboxes. If the checkbox is unchecked, it will not be present in the postdata. Below is my generic save function for Term Meta, it will delete a value if it was stored previously but is no longer available.

/**
 * Save Term Meta
 */
add_action( 'create_my_taxonomy', 'tsg_save_term_meta', 10, 2 );
add_action( 'edited_my_taxonomy', 'tsg_save_term_meta', 10, 2 );

function tsg_save_term_meta( $term_id )
{
    $term_meta = $_POST['term_meta'];

    if ( !empty( $term_meta ) )
    {
        $term_meta_old = get_term_meta( $term_id );
        foreach ( $term_meta_old as $meta_key => $meta_value )
            if ( !array_key_exists( $meta_key, $term_meta ) )
                delete_term_meta( $term_id, $meta_key );

        foreach ( $term_meta as $meta_key => $meta_value )
            update_term_meta( $term_id, $meta_key, $meta_value );
    }
}

When you’re all finished converting and everything is sweet. You’ll probably want to clean up your options table. Use this function at your own risk.

/**
 * Delete All Taxonomy Term Options - USE AT YOUR OWN RISK
 */
global $wpdb;

$wpdb->query( $wpdb->prepare("
        DELETE FROM " . $wpdb->prefix . "options
        WHERE option_name LIKE %s
    ",
    array( 'taxonomy\_%' )
));