How long is "a very long time." Be specific: on what date did you surrender possession of the premises, and on what date did you receive an itemized list of deductions from your deposit and additional charges?
What would make you think it might not be legal? Are you suggesting that you thought your liability for damages was capped by the amount of your deposit?
P.S. When you click the link to the landlord tenant laws that "adjusterjack" provided, pay particular attention to Civil Code section 1950.5(g)(1).

