Preface:  I originally posted this on Reddit, and I thought this would make a suitable first post for this blog. 
Stormtrooper accuracy is  something of a joke on the internet.  They never seem to hit any  important person when they shoot at them, missing constantly.  There's a  Cracked article on it, for god's sake.  Everyone has heard the joke.
It's a complete and total lie, and it ignores the relevant details of the events.
To prove that they are, in fact, crack shots, watch the opening  sequence in A New Hope.  Here we have a number of stormtroopers charging  into a narrow breach into heavy fire, yet they are able to gun down  more rebel soldiers in cover than they take in casualties!  This is not  amateur night here--these are stone cold killers, destroying their foes  mercilessly.  They are so effective that the defenders fall back almost  immediately.
Then, the next time their accuracy is mentioned, it is in the  examination of the corpses of a bunch of child-sized aliens.  That's  right, they were able to kill a number of small targets with expert  precision.  Now, it was off-screen, but you cannot get that kind of  consistency and precision randomly.  It beggars the imagination to think  that their aim is terrible.
So why can they never hit Luke and Leia in the Death Star?  They were ordered not to.   The escape was allowed--recall that Tarkin and Vader discussed exactly that  the minute the Falcon left.  They needed the princess to go to the  hidden fortress so they could track them there.  She already had refused  to give them accurate coordinates, even as her homeworld was destroyed  before her eyes.  She would never break, never talk.  So she had to  escape.
Now, killing the one guy escorting her to the ship, or any of the  vital crew to the small craft, would be counter-productive to that  enterprise.  But, they have to make it look good.  The escape triggered  an alarm.  Even if it hadn't (highly unlikely--they command was far too  competent at their jobs to let anything slip through), Vader knew that  an escape was on--he felt the presence of Obi-wan.  Vader is quite  competent, and so would have certainly alerted command to this.  After  all, he did have a discussion about it with Tarkin before seeking out  Obi-wan.
The only reasonable conclusion then is that the stormtroopers,  fanatically loyal and dedicated to the cause, were ordered to attack but miss  when doggedly pursuing these escaping prisoners.  And, miss by a small  enough margin that it looks good.  Recall the bridge scene--blaster fire  was erupting around the edges of the doorframe that they were standing  on--inches from serious harm.  Yet, despite that large volume of fire,  in single-shot mode, no hits were scored.  And well it was that none  did!  Had a single shot hit the princess, it could have killed her.  It  could have wounded her severely enough that escaping with her would have  been implausible, and they would have instantly been alerted to the  fact that it was a set-up.  Even if it had been non-lethal in nature, it easily could have crippled her, making escaping with her impossible.
It nearly was--Leia thought it too easy.  However, any hit would have made it obvious if they did escape, since even if it wasn't lethal, it would have dramatically slowed the party down, destroying any illusion.
As such, from A New Hope, all evidence is that they are, in fact,  excellent shots and quite loyal, willing to die for the cause without a  moment's hesitation on the order of Lord Vader.
One could argue, terribly, that it is simply the quality of the  weapon that is a problem.  That is patently absurd.  The Empire has the  resources to build a space station the size of a small moon without being noticed.   It wasn't public knowledge that the Death Star was built--it came from  nowhere and blew up a planet.  No one believed that possible until it  happened, which was the point.
This means that they have a logistical train that routinely delivers  massive amounts of material across the galaxy, such that it draws little  real attention.  This cannot be cheap--the cost of transport alone  would be immense.  But they are somehow buying weapons on the cheap?   That makes no sense.  They'd make sure that these things were very  accurate, and consistent, before the purchase of every lot.  Their  quartermaster corps would see to that, and they must be sufficiently  competent to do so because they were able to build a moon in secret.   That's no mean task.  So their weapons must be accurate.
Ignoring that, it still remains the fact that recently looted  weapons, from the very racks that these stormtroopers drew from, were  quite accurate in the hands of other people who just picked them up and  had not drilled extensively on them.  These must be accurate weapons  indeed, or the Hand of God Himself intervenes upon every shot ensuring  the safety of the heroes and the death of the villains.  And, if these weapons were wildly inaccurate, fired by morons barely capable of shooting, the sheer volume of fire directed at the escapees should have felled one of them. 
An alternate explanation proffered by a Redditor was that the Force was strong in Luke and Leia (and Han and Chewie as well), and that twisted fate to protect them so their destinies could be lived out.  That is also an acceptable response, and certainly would feed into this as well.  But, for the purposes of this article, I am not putting this as a primary factor.  Again, the plan of Tarkin and Vader was to see the princess escape, so the war could be won. 
Now, consider Empire Strikes Back.  We see very little of the battle  of Hoth, but we do see them rapidly assembling a heavy weapon even as  they take automatic weapon fire, without a moment's hesitation.  That  requires immense discipline and skill.  This goes, again, to  demonstrating their intense competency.  You do not acquire such  coolness under fire without intense and rigorous training.  Are we then  to believe that they train to just set weapons up, but not fire them  accurately?  Please. 
So, on Cloud City, we again see a large contingent of stormtroopers  not hitting the escaping princess and retinue.  Again, this is clearly by design.  Darth Vader had the hyperdrive disabled--he asked his subordinates this on his command ship.  They weren't going anywhere.
However, he needed a back-up plan.  They weren't going to leave  without Luke, and he wanted his son captured.  So he again ordered them  to be allowed to escape, but to make it look good.  They weren't going  anywhere anyhow--they'd just be going straight into the shuttle bay of a  Star Destroyer, unable to jump to hyperspace.  He knew that Luke had  been developing his skills, so it is not unreasonable to assume that he  could send a message via the force to effect an extraction.  Luke could  flee, and Luke is certainly clever and skilled enough to find a way past  guards--or at least, past enough that he could get out.  Then, the  Falcon would "rescue" him, leave atmosphere, and promptly be captured,  leaving Luke firmly in the hands of Vader.
And why the Falcon?  What other ship would Luke trust, implicitly?  This is a back-up plan, a contingency.   
Lobot being able to lead a security detail anywhere? There were enough storm troopers to garrison the city, so why allow local cops to do anything?  Their loyalty hasn't been established, or really built up at all.  They can't be trusted. That's  either a gross oversight, one that is unbelievable given that Vader  himself ordered the Falcon to be disabled, or deliberate.  He knew  Calrissian would attempt to break the Princess and Chewie out--why do  you think he kept altering the deal, pushing it well beyond the  boundaries that Lando would accept?  Did he think that Lando would  simply go along with this, without resisting?  Surely not.  Remember, the goal was them to get on the Falcon, because it wasn't going anywhere no matter what.  
It has been pointed out to me, on Reddit, that Vader could have sent a cloudcar to pick Luke up.  However, as a contingency, this leaves much desired.  First of all, the pilot would be susceptible  to Jedi mind tricks, which Vader suspected Luke was capable of--hence the capture mission.  Even if he did get picked up, Vader assumed that Luke was capable of sending messages via Force-telepathy.  A cloudcar, piloted by mooks, was not reliable enough.
This leaves the final movie, Return of the Jedi.  Again, we see  nothing but extreme competency and accuracy on the part of the  stormtroopers in battle.
During the battle, we never see the results of their pot-shots  against rebels or Ewoks, but we do see them laying down a consistent  volley of fire, with disciplined shots, and constant ducking back to  cover.  One could argue this would mean inaccurate shots, but given the  first movie's opening sequence, that is hard to believe.  They were  using the sights to aim, instead of firing from the hip, during this  fight and on the ship combat, they did not bother aiming carefully.   It's hard to believe they lose any accuracy at all when using a more  carefully aimed approach.
So what direct evidence do we have of their shooting?  When Han and  Leia are attempting to break into the bunker, two successive pot-shots  hit a child-sized object behind partial cover, instant disabling the  droid, and inflicting a potentially serious wound on Leia.  Again, these  were shots taken under hasty aim against targets behind cover, while  shots were going towards them.  This is not an easy thing--ask an  infantryman if you disbelieve me.
There are lingering questions about the effectiveness of their armor.  It does seem that a shot from a blaster takes them down, no problem.  However, this doesn't necessarily mean killed--after all, the armor certainly absorbs impact and energy is transferred to it in any shot, which necessarily lessens the severity of any penetrating shot.  In order to be effective versus armored foes, weapons would have to have an increased energy output if they are supposed to be lethal.  That means fewer shots per weapon, which is vital in a firefight. 
Also, the attacks by Ewoks call into question the strength of the armor.  However, it should be noted that we see no kills inflicted by Ewoks, except in special circumstances.  When they directly attacked stormtroopers, with the element of surprise, they were able to drive the Imperials back, or interrupt their firing, or otherwise impede their fighting capabilities.  In a battle, these hindrances can weigh heavily against a force.  The Ewoks didn't have to defeat the Stormtroopers, they only had to occupy them while the Rebel soldiers mopped them up.
The evidence is clear--Stormtroopers are quite accurate and effective  soldiers, with top of the line equipment.  Claiming otherwise is  slander.