At the beginning of the movie Thor, Mjolnir is not enchanted. It's just Thor's war hammer, built for him by whoever makes Asgardian weapons. He uses it because it's his, with no other particular requirements.
After the fiasco with the Frost Giants, Odin places an enchantment on the weapon -- this is what he's doing when he whispers into the hammer, just before sending both it and Thor to Earth. You can see this in the Thor Transcript.
Odin holds Mjolnir in his hand, stares at it bitterly. He
closes his eyes, lost in contemplation, whispers something
quietly.
ODIN (CONT'D)
(WHISPERING)
Whosoever holds this hammer, if he
be worthy, shall possess the power
of Thor.
RUNES appear on the side of the hammer, as if carved into its
smooth surface. The runes linger for but a moment, then
disappear. Suddenly, Odin turns and hurls the hammer into
the Bifrost.
At this point, Thor isn't worthy of the weapon, as we can see when he tries to lift it and fails.
By the end of the movie, his character has grown more humble and more worthy by nature of having to confront his own flaws. When he finally
sacrifices his life to save the town
he becomes worthy of the hammer, and remains so from then on.
It's important to note that the definition of "worthy" here is the Asgardian definition. There are likely things about it that may seem unusual to us, but imagine as a rough estimate what a Viking might think of as worthy. Being brave in battle, being able to defeat enemies, defending the weak and helpless, putting yourself in harms way for the sake of others, etc. These are the things that appear to qualify as worthy.
Being obnoxious, or a braggart, or a drunk, or promiscuous -- none of these things really detract from someone's "worthiness" to wield a weapon of battle. They may be things that we see as detrimental to someone's personality, but in the eyes of Odin's enchantment, as long as that person continues to exhibit the virutes it cares about, everything else is irrelevant.
Also note that, at least in the source material, many other people are equally as worthy as Thor to wield Mjolnir. Besides Vision, we haven't seen that happen in the MCU yet, but there was a hint of it in Age of Ultron -- Steve Rogers did move Mjolnir ever so slightly from its resting place. This wasn't a mistake either -- the camera cuts to Thor who clearly noticed and was worried, before relaxing when Rogers fails to lift it. Whether this was just an Easter Egg for comics fans, or it was a hook for future development, remains to be seen.