As a module

How about make and use password module?
(I don't test this code. But It's work fine maybe. :D)

Cheers.