A finite commutative ring with the property that every element can be written as product of two elements is unital I was struggling  for days with this nice problem:

Let  $A$  be  a finite commutative  ring such that every element of $A$  can be written as product of two elements of $A$. Show that $A$  has a multiplicative unit  element.

I need a hint for this problem, thank you very much.
 A: HINT $\ $ The hypothesis implies that $\rm\:A^2 = A\:.\:$ Therefore, by invoking the simple Lemma in this answer, we deduce that $\rm\:A\:$ is principal, generated by an idempotent.
NOTE $\ $ The cited Lemma is a generalization of the proof hinted by Jonas (and Pierre). As here, this Lemma often proves handy so it is well-worth knowing.
A: This can be solved using Nakayama's lemma. The first version stated in the linked article is quoted below.  The Wikipedia article includes a proof and a reference to Commutative ring theory by Matsumura.

Let $R$ be a commutative ring with identity $1$. . . . Let $I$ be an ideal in $R$, and $M$ a finitely-generated module over $R$. If $IM = M$, then there exists an $r \in R$ with $r \equiv 1$ (mod $I\ $), such that $rM = 0$.

Consider what happens when $R$ is the unitalization$^1$ of $A$, and when $I$ and $M$ are both $A$.
$^1$ The unitalization of $A$ can be defined as $R=A\times \mathbb Z$ with the operations $(a,m)+(b,n)=(a+b,m+n)$ and $(a,m)(b,n)=(ab+mb+na,mn)$.
A: Let $a$ be an element of $A$. Then $a$ can be expressed as product of two elements, each of which can be expressed as a product of two elements, and so on forever.  By the finiteness of $A$, among these expressions for $a$, some $y\in A$ appears to arbitrarily high powers. 
Again by finiteness, we have $y^i=y^j$ for some positive integers $i<j$.  Take a representation of $a$  as a product that uses a power of $y$ which is $i$ or greater.  Then $i$ of these $y$'s can be replaced by $j$ $y$'s. This procedure does not change $a$, but it multiplies $a$ by $y^{j-i}$. Thus $a=y^{j-i}a$, and therefore there is an identity element for $a$.
We conclude that there is an identity element $1_a$ for every $a\in A$.
Now apply repeatedly the following easy to verify lemma:
Lemma: If $1_u$ is an identity element for $u$, and $1_v$ is an identity element for $v$, then $1_u+1_v-1_u1_v$ is an identity element for both $u$ and $v$. (By $s-t$ we mean $s$ plus the additive inverse of $t$.)
Comment: An equivalent way to finish the argument is to let $M$ be a maximal subset of $A$ for which there is a $u\in A$ such that $um=m$ for all $m\in M$. If $M$ is not all of $A$, we can use the lemma to extend $M$. 
Or else we can obtain an explicit and even symmetric expression for a unit in terms of all the $1_a$.
