refactoring algorythm of generate password