You need a storage location possibly SQL where you store the username and occurred time of a failed log in:
Username VARCHAR(255),
Occurred DATETIME
The the following SQL will give you the failed login count.
SELECT [Count] = COUNT(*) FROM dbo.FailedAttempts WHERE Username=@Username AND Occurred > DATEADD(MINUTE, -30, GETDATE())
You then need to build this into you login process so that if the user login fails you insert into the failed attempts table. If the password is valid you check the current failed attempts count and reject their attempt where it's too high.