Updated password check function to reduce checks