A law student who dealt drugs from his Hatfield home because he was short of money was jailed for three years on Friday.
Brian Coughlan, now 22, had finished his first year at Hertfordshire University when he was stopped by the police riding a bike in the middle of the road in August 2012.
The officers could smell cannabis and went back with him to his home in Dragon Road and, in his second floor bedroom, they found a locked safe, St Albans crown court was told.
Prosecutor Philip Misner said Coughlan handed over the keys to the safe. Inside they found more than 30 wraps of cocaine weighing a total of 5.69 grams and £845 cash. Cannabis was also discovered, along with two sets of scales, two mobile phones, two iPhones, an iPad and a knife showing traces of cocaine.
The phones were examined and text messages had references to B - brown for heroin and W - white for cocaine.
Coughlan pleaded guilty to conspiracy to supply Class A drugs. He had no previous convictions.
Defence barrister, Sherry Nabijou, said he had made a "massive error of judgement."
She said: "He had just completed his first year of a law degree, but now will never be able to practise." His decision to sell drugs was a mistake, she said.
Jailing him, Judge John Plumstead said: "Crack cocaine is a catastrophic blight on society. Those who take it surrender their free will and go on to live miserable lives. Nobody took the decision to sell crack cocaine by mistake."