Let p be an odd prime. Prove that x^2 ≡ 2 (mod p) has solutions if and only if p ≡ 1 or 7 (mod 8).

The related materials in the section are quadratic residues, and the Legendre symbol, but I can't figure out how to prove this.

Any help is appreciated!

[also under discussion in math links forum]