login query logical improvment