Let $X = \operatorname{Spec} A$ and $Y=\operatorname{Spec} B$ be affine schemes. For a ring homomorphism: $\varphi: B\rightarrow A$, we know that it naturally induces a morphism of locally ringed spaces $f: X\rightarrow Y$. Hartshorne discussed that this correspondence is surjective in chapter 2. However, what I have difficulty seeing is that this correspondence is injective. That is, given two ring homomorphisms $\varphi\_1,\varphi\_2: B\rightarrow A$ inducing the same morphism $f$, then $\varphi\_1=\varphi\_2$ necessarily.

I know that for the induced morphism $f^\sharp: (Y,\mathcal{O}\_Y)\rightarrow(X, \mathcal{O}\_X)$ one has, the map of stalks $f^\sharp\_\mathfrak{p}$ is the localized map ${\varphi\_1}\_\mathfrak{p}= {\varphi\_2}\_\mathfrak{p}$ for all $\mathfrak{p}\in Y$. How does one deduce from here that $\varphi\_1=\varphi\_2$?

I feel like I am missing something out simple so any help given would be greatly appreciated!