Constrained random-phase approximation