Fix repeat authentication attempts, closes #321.