Improved password validation logic