Password is now regenerated when the password type is changed.
Added some checks to avoid exceptions in the case of bad input data.