1) Even though it is forbidden to recite verses from the written part of the Torah by heart, those verses which everyone knows fluently, such as the Shema or the priestly blessings, are permitted. (Shulchan Aruch and Mishne Berurah 48)
2) A blind man or someone in prison without a text, may recite verses by heart, as it says “There is a time to act for Hashem, they annulled your Torah!” (ibid)