Storing password (functions.php)

Here ya go:

function dopasswordstuff(){
   if(isset($_POST['homepagepassword'])) {
    global $wpdb;
    $post_password = trim($_POST['passwordfield']);
    $post_id = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_password = %s", $post_password) );
    if (!empty($post_id)) {
      if ( empty( $wp_hasher ) ) {
        require_once( ABSPATH . 'wp-includes/class-phpass.php' );
        // By default, use the portable hash from phpass
        $wp_hasher = new PasswordHash(8, true);
      }
      // 10 days
      setcookie( 'wp-postpass_' . COOKIEHASH, $wp_hasher->HashPassword( stripslashes( $post_password ) ), time() + 864000, COOKIEPATH );
      wp_redirect(get_permalink($post_id));
    }
    exit;
  }
}
add_action('template_redirect','dopasswordstuff');

I cribbed some stuff from the Core post login system and I believe I got it working. The trick is to set the cookie, which required adding this part:

if ( empty( $wp_hasher ) ) {  
     require_once( ABSPATH . 'wp-includes/class-phpass.php' ); 
     // By default, use the portable hash from phpass
     $wp_hasher = new PasswordHash(8, true);
}
// 10 days
setcookie( 'wp-postpass_' . COOKIEHASH, $wp_hasher->HashPassword( stripslashes( $post_password ) ), time() + 864000, COOKIEPATH );