Prove that if the complex function $|f(z)|^2$ is constant in $D$ and $f(z)$ is analytic in $D$, then $f(z)$ is constant in $D$. My proof:
Let $|f(z)|^2 = M$ for $z\in D$. 
Then $f(z) = \pm\sqrt{M}$ (not sure about this step, are there only two values for the square root of a complex number> No right? Could be more. But I don't think it would change the essence of the proof)
But $f(z)$ is analytic in $D$ so it cannot be the case that $f(z_1) = \sqrt{M}$ and $f(z_2) = -\sqrt{M}$ for $z_1,z_2\in D, z_1 \neq z_2$.
So $f(z)$ is constant in $D$

Does this proof make sense? How do I account for the non-principal values of the square roots of $M$?
 A: If $\mid f(z)\mid^2= M$ then the image of $f$ is contained in a circle. By the open mapping theorem, $f$ is constant.
A: If you've already seen the maximum modulus principle and/or the open mapping theorem, the problem becomes trivial. Here's a proof using just the Cauchy-Riemann equations:
Write $f$ as a function of two real variables: $f(x,y)=u(x,y)+iv(x,y)$. We are given $u(x,y)^2+v(x,y)^2 \equiv M$. Differentiating both sides with respect to $x$ gives $2uu_x+2vv_x=0$, and doing the same for $y$ gives $2uu_y+2vv_y=0$. Rewrite these two equations as a single matrix equation, and take the determinant of the matrix, using the Cauchy-Riemann equations. You should get $u_x^2+u_y^2$. so, whenever $f(x,y) \neq 0$ (hence by continuity $f$ is nonzero in a neighborhood of $(x,y)$), you can deduce that the matrix is singular, hence $u_x^2+u_y^2=0$, but then all first order partials of $u$ and $v$ must be zero, hence $f$ is constant in a neighborhood of every $z$ with $f(z) \neq 0$. Of course, $f$ is also constantly zero on the complement of this set. Now since $f$ is continuous, you can see that $f$ is constant using a connectedness argument.
