Thursday, February 7, 2008

Custom Security MembershipProvider & Login attempts (MaxInvalidPasswordAttempts)

The Problem : Have a limit on the amount of possible logins when using a Custom provider.

Let's say that you write your own MembershipProvider (quite common if you want to use your own object model ..)

   11   public class MyMemberShipProvider : System.Web.Security.MembershipProvider
   12     {

Like many other articles explain, the most important Method is ValidateUser.
What very people often "forget"to mention is that all other features are not present in your provider. For example, the MaxInvalidPasswordAttempts is a property that you can set it to any number but nothing is going to happen.

In a Nutshell : you need to implement it yourself.

What I am showning below is a quite simple version but it's proves the point.

  180     public override System.Boolean ValidateUser(System.String pUsername, System.String pPassword)
  181         {
  182             if (pUsername.Equals("demo") && pPassword.Equals("demo"))
  183             {
  184                 return LoginSuccess();
  185             }
  186             return LoginFailed();
  188         }

LoginFailed() will basically return false but also it would do the check if another attempt should be granted or not:

  211     private bool LoginFailed()
  212         {
  213             //WebFailureAuditEvent.Raise(WebEventCodes.AuditFormsAuthenticationFailure);
  214             LoginFailuresCount++;
  215             if (LoginFailuresCount >= this.MaxInvalidPasswordAttempts)
  216                 throw new Exception("OK, that's it. Bye Bye");
  218             return false;
  220         }

You need to keep track of how many login failures :

  197  protected int LoginFailuresCount
  198         {
  199             get
  200             {
  201                 if (HttpContext.Current.Session["Failures"] == null)
  202                     return 0;
  203                 return (int)HttpContext.Current.Session["Failures"];
  204             }
  205             set
  206             {
  207                 HttpContext.Current.Session["Failures"] = value;
  208             }
  209         }

In the commented line where I was trying to Raise the "WebFailureAuditEvent", I read somewhere that I was a good idea to raise it but could not find any reference or example. If anybody knows how to do it --> please let me know.

Note: An improvement to this model would be to support "PasswordAttemptWindow" which in this case I did not implement.

Note: New Browser == new Session so it's not really state-of-the-art security technique it's a basic


Anonymous said...


I was looking for a post about MembershipProviders and noticed your question about the WebFailureAuditEvent. This is part of the built-in Health Monitoring events. Raise this event like this:

WebFailureAuditEvent MyEvent = new WebFailureAuditEvent(string message, object eventSource, int eventCode);


More about Health Monitoring:

Sebastian Talamoni said...

Thanks for the Tip!

Anonymous said...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Smartphone, I hope you enjoy. The address is A hug.

Anonymous said...

I just found the website who reviews about
home business opportunity

If you want to know more here it is
home business ideas

Anonymous said...

I will not concur on it. I over precise post. Particularly the title attracted me to read the intact story.

Anonymous said...

Nice post and this mail helped me alot in my college assignement. Thanks you on your information.

Anonymous said...


[b]Xrumer SEO Professionals

As Xrumer experts, we possess been using [url=]Xrumer[/url] for a sustained fix for the time being and know how to harness the massive power of Xrumer and go off it into a Cash machine.

We also provide the cheapest prices on the market. Numberless competitors devise order 2x or even 3x and a end of the opportunity 5x what we pervade you. But we feel in providing enormous help at a low affordable rate. The unbroken direct attention to of purchasing Xrumer blasts is because it is a cheaper surrogate to buying Xrumer. So we plan to stifle that thought in cognizant and yield you with the cheapest censure possible.

Not solitary do we take the most successfully prices but our turnaround heyday for the treatment of your Xrumer posting is super fast. We intention have your posting done in the forefront you know it.

We also produce you with a sated log of loaded posts on different forums. So that you can notice for yourself the power of Xrumer and how we hold harnessed it to gain your site.[/b]

[b]Search Engine Optimization

Using Xrumer you can wish to realize thousands upon thousands of backlinks in behalf of your site. Scads of the forums that your Place you will be posted on get great PageRank. Having your tie-in on these sites can categorically mitigate strengthen up some top-grade rank recoil from links and really aid your Alexa Rating and Google PageRank rating owing to the roof.

This is making your site more and more popular. And with this inflate in celebrity as well as PageRank you can keep in view to witness your place in effect superiority gamy in those Search Mechanism Results.

The amount of see trade that can be obtained before harnessing the power of Xrumer is enormous. You are publishing your site to tens of thousands of forums. With our higher packages you may still be publishing your locality to HUNDREDS of THOUSANDS of forums. Create 1 collection on a in demand forum drive usually enter 1000 or so views, with say 100 of those people visiting your site. Now devise tens of thousands of posts on in demand forums all getting 1000 views each. Your freight will withdraw through the roof.

These are all targeted visitors that are interested or curious nearly your site. Envision how many sales or leads you can execute with this great gang of targeted visitors. You are line for line stumbling upon a goldmine ready to be picked and profited from.

Reminisce over, Traffic is Money.


Anonymous said...

[url=]hip hop jewelry[/url],[url=]hip hop pendants[/url],hip hop watches,[url=]bling bling[/url] ,hip hop,[url=]hip hop chains[/url],hip hop bling,[url=]iced out chains[/url],[url=]wholesale chains[/url]
hip hop jewelry
wholesale hip hop watches
hip hop rings

Anonymous said...

Confirmation Our Risqu‚ Prices at, The Unequalled [b][url=]Online Chemist's workshop [/url][/b] To [url=]Buy Viagra[/url] Online ! You Can also Details to Greater Deals When You [url=]Buy Cialis[/url] and When You You [url=]Buy Levitra[/url] Online. We Also Have a Mammoth Generic [url=]Phentermine[/url] In impaired of Your Victuals ! We Huckster Exchange signpost [url=]Viagra[/url] and Also [url=]Generic Viagra[/url] !

Anonymous said...

Someone deleted a variety of links from and megaupload servers.

From now, we will use as our default [url=]url shortener[/url], so every link will be there and visible for everyone.

You can choose from several great [url=]short url[/url] address like: and many others.

They have over 60 other available domains and the [url=]url shortener[/url] service work properly for free without any registration needed.

So we think it is good notion and propose you to use [url=]url redirect[/url] service too!

Thank you.

Anonymous said...

I'm new around here, seems like a cool place though. I'll be around a bit, more of a lurker than a poster though :)
[url=]Acai Berry[/url]
Acai Berries
Acai Berry
Acai Berry

Anonymous said...

my kaspersky 2010 antivirus is not updating and i am not able to open kaspersky website and other sites like avast.this problems are happening after i have done my pc's formatting [url=]santoramaa[/url]

Anonymous said...

Hi readers
Do not miss your chance to get a free iPhone 4G. Visit

Anonymous said...

[b]Website Traffic[/b]

A new way to get traffic to your website. Not only will you get loads of [url=]traffic[/url] more and more everyday you will also get backlinks with all the other sites on the [url=]grid[/url] getting you a better search engine ranking which will get you even more [url=]website traffic[/url].Get on the pixel grid today and let the traffic come to you.Taking the internet by storm.The new way to advertise.


Anonymous said...


A balance must be achieved between the desire for innovative design and the realities of traditional operating and maintenance practices. Durability, ease of maintenance and material innovation are all incorporated into Mansour Engineering approach.

[url=] click here to go to Mansour Engineering[/url]

Anonymous said...

Good evening

We do not agree with this year BRITs 2010 decision.

Please go to see our little web survey

Lady Gaga can not be better than Nina Hagen

Poll supported by BRIT awards 2010 sponsor femmestyle

Pet Shop Boys surprise lucky BRITs fan with a MasterCard Priceless Gig in their living room

Anonymous said...

You could easily be making money online in the underground world of [URL=]blackhat seo[/URL], You are far from alone if you have no clue about blackhat marketing. Blackhat marketing uses alternative or not-so-known ways to generate an income online.

Anonymous said...

It isn't hard at all to start making money online in the undercover world of [URL=]blackhat cpa methods[/URL], Don’t feel silly if you haven’t heard of it before. Blackhat marketing uses not-so-popular or misunderstood avenues to produce an income online.

Anonymous said...

zovirax cream online pharmacysubstitue drugs for zelnorm
[url=] buy vicodin [/url]

Anonymous said...

[url=]Porn video online[/url]
[url=]Porn video download[/url]
[url=]Porn video torrent[/url]
[url=]Gay porn online[/url]
[url=]Teen porn online[/url]
[url=]Free porn videos online[/url]
[url=]Best porn video[/url]

Anonymous said...

Escape Sluggish Downloads Use NZB Files You Can Instantly Find Movies, Console Games, MP3 Singles, Software and Download Them at Accelerated Speeds

[URL=][B]NZB Sites[/B][/URL]

Anonymous said...

Hello i am new here. I found this board very helpful & its helped me out loads. i should be able to help out and help other people like it has helped me.

Personally i enjoy [url=]watch family guy online free[/url] to helps pass some of time.

Thanks all, See you about.

Anonymous said...

Generic Viagra is the world renowned medicine for erectile dysfunction and most men have forgotten they ever had a problem with erections after its use. Take it on empty stomach and it will work in 30 minutes. Erections can be achieved on stimulation.Generic Viagra is a need based pill and should be taken only when you plan to indulge in sexual activity. Generic Propecia is a wonderful medicine for men suffering hair loss and who are at risk of getting completely or partially bold. Propecia can also help you at the beginning stages of some prostatic problems. Viagra improves erections for most men no matter how long they have had erectile dysfunction, taken approximately 30 minutes before your plan of sexual activity and works on stimulation for around 4 hours.Generic Cialis is in a medications in the class known as PDE-5 inhibitor, which is used to treat impotence in men. Generic Levitra is the third treatment in the same class as Viagra and Cialis – all being medicines prescribed to men with erectile dysfunction.

Anonymous said...

I am reading this article second time today, you have to be more careful with content leakers. If I will fount it again I will send you a link

Anonymous said...

link for [b]download software for windows[/b] is available at:

download software for windows
[url=http://www.downloadsoftwareforwindows]download software for windows[/url]

[url=http://www.downloadsoftwareforwindows/products/download-3gp-video-converter/productpage.php]download 3gp video converter[/url]

download youtube to mp3 converter

Anonymous said...

site for [b]buy software for windows[/b] are available here:

buy software for windows
[url=]buy software for windows[/url]

[url=]buy youtube buyer[/url]

buy dvd to iphone converter

Anonymous said...

link for [b]download software for windows[/b] is available here:

download software for windows
[url=]download software for windows[/url]

[url=]download calculator[/url]

download tetris