We have an odd prime with $(-2|p)= 1.$ That is, we can solve $w^2 \equiv -2 \pmod p.$ So now we have $w^2 = -2 + p t.$ Which looks more impressive as $$ p t - w^2 = 2. $$ Or $$ \det \; \left( \begin{array}{cc} p & w \\ w & t \end{array} \right) \; = \; 2 $$ We have constructed the positive binary quadratic form $f(x,y) = p x^2 + 2 w x y + t y^2,$ or in shorthand $ \langle p, 2 w, t \rangle. $

Now, any positive binary quadratic form can be reduced in the sense of Gauss. That is, a replacement form can be produced, call it $ \langle a, 2 b, c \rangle, $ with the same determinant $ac-b^2 = 2$ and $0 \leq |2b| \leq a \leq c, $ also $a > 0$ and $2b \neq -a.$ It is not difficult to show by inequalities that the only such reduced form is actually $ \langle 1,0,2 \rangle. $ This property is called "class number one."

See REDUCTION DEMO.

Now, what is this about reduction? It means we can find an integral matrix of determinant $1,$ call it $$ P = \left( \begin{array}{cc} \alpha & \beta \\ \gamma & \delta \end{array} \right) $$ with transpose $$ P^T = \left( \begin{array}{cc} \alpha & \gamma \\ \beta & \delta \end{array} \right), $$ such that $$ \left( \begin{array}{cc} \alpha & \gamma \\ \beta & \delta \end{array} \right) \left( \begin{array}{cc} p & w \\ w & t \end{array} \right) \left( \begin{array}{cc} \alpha & \beta \\ \gamma & \delta \end{array} \right) \; = \; \left( \begin{array}{cc} 1 & 0 \\ 0 & 2 \end{array} \right). $$ So far, so good. As $P$ has determinant $1,$ it is easy to find its inverse, and we find $$ \left( \begin{array}{cc} \delta & -\gamma \\ -\beta & \alpha \end{array} \right) \left( \begin{array}{cc} 1 & 0 \\ 0 & 2 \end{array} \right) \left( \begin{array}{cc} \delta & -\beta \\ -\gamma & \alpha \end{array} \right) \; = \; \left( \begin{array}{cc} p & w \\ w & t \end{array} \right). $$

Well. If you carefully multiply out the matrices, you see that $\delta^2 + 2 \gamma^2 = p.$ It's a good thing.

AFTERSHOCK: the situations where this argument works in its entirety are these: for a positive form $ \langle a,b,c \rangle, $ where $b$ is allowed to be odd, we take the discriminant $\Delta = b^2 - 4 a c$ which is negative, and the same quantity as in the "quadratic formula." The argument works for primes with $\Delta \neq 0 \pmod p$ and $(\Delta | p) = 1,$ when, in addition, there is only one class per genus and we know the necessary congruence information on $p,$ or when there are exactly two classes per genus, and we are asking about a genus made up of a form and its opposite class, in symbols $ \langle a,b,c \rangle $ and $ \langle a,-b,c \rangle. $ For example, we can describe the primes represented by $3 x^2 + 2 x y + 5 y^2$ entirely by congruences, although doing that for $x^2 + 14 y^2$ or $2 x^2 + 7 y^2$ is a fair bit of Cox's book. Finally, I would like to emphasize that this works for indefinite forms, which are treated in Buell's book but not in Cox's. All that happens is that there are typically multiple reduced forms in a given equivalence class, that does not hurt the argument. I just saw a new question with indefinite, discriminant $5,$ but I'm not going to type all that.