At the end of season 3, Shaw and Root break into a Samaritan sever facility to place 7 servers that have been altered to ignore 7 cover identities in its hunt for the Machine and her allies. The first 6 servers contain one simple identity that, if compromised, can be targeted upon by Samaritan and Decima. These identities are given to Reese, Finch, Shaw, Daizo, Jason Greenfield and Daniel Casey. Although Root does receive a cover similar to the others to protect herself, her identity is different as that her cover can be compromised and re-established, as well as changed in order to help The Machine combat Decima, several times without arousing suspicion from Samaritan.
Anything history prior to Samaritan coming online did not actually happen and was simply fabricated. Within that fabricated story, Reese leads many to believe that he and Carter were rather close friends and he was undercover when she was murdered and that her death is the reason he has taken certain actions, such as record high number of shooting incidents or assisting an IAD officer, which can be considered reckless behavior. Immediately after starting to pose as Riley, Reese started to work undercover at Narcotics, arresting some serious players in the drug world.
Trying to stop a Presidential assassination, Reese uses his badge as John Riley to try to get into a fundraiser. When Logan Pierce arrives, Reese claims that his job is to protect Pierce who gets Reese inside the fundraiser. After the assassination is stopped, Pierce reveals that his team got Reese and his team as an irrelevant number to protect. When Pierce gives Reese the paper with the number, the number is shown to be Detective John Riley. Pierce comments that once he realized Riley was actually Reese, it was easy to determine he was the victim and not the perpetrator, something Pierce claims took the fun out of it. (“Synecdoche”)
Samaritan is able to get Root's cochlear implant and as a consequence learns of the Team's cover identities. In response, Samaritan gives an anonymus tip to the police that John Riley is actually the Man in the Suit, resulting in Reese and Fusco's lieutenant turning on them. They are then apprehended by cops bribed by Samaritan to murder them but are rescued by Finch and snipers hired by Thornhill Corporation. Despite Reese's identity as Riley being exposed along with Fusco's association with him, Fusco is able to retain his job after Samaritan is destroyed. (“return 0”)