3

I have always been told that writing your own login method (e.g. validate user given the username and password) is bad practice, and that one should reuse existing libraries for that. I have always believed that, but I am looking for practical threats in such a scenario (C#). The practical case I am looking into is customizing a login method to include the validation of a Captcha. I haven't found any existing library to do that inside the authentication logic.

One of the implications of my custom implementation is that the validation method does not return a bool, but another type. May this pose a danger?

1
  • I'm not sure whether you're asking a specific practical question or not! If not, Graham Hill is right on the money. Maybe you should ask another with the specifics of your C# implementation? Jul 29, 2014 at 13:39

3 Answers 3

6

The danger is expressed in Schneier's law:

any person can invent a security system so clever that he or she can't imagine a way of breaking it.

The only way anyone knows to test if any given system is secure is to have lots and lots of clever people try to break it over a long period of time. You won't have that with a system you rolled yourself.

1

...but I am looking for practical threats in such a scenario (C#)

There are a huge number of ways that you could introduce a vulnerability by rolling your own login. A few that come to mind:

User enumeration - I've seen people who give descriptive messages when a login fails ("user does not exist", "user exists, but password was incorrect", etc.) instead of a generic "login failed" message.

Insufficient lockout policy - This would allow a malicious user to bruteforce username/passwords. This is extra dangerous if you have the User enumeration vulnerability mentioned above.

Not performing login action over HTTPS - Could allow for a man in the middle attack when someone logs in.

As I mentioned there are a number of other potential vulnerabilities that you should watch out for (SQLi, XSS, the list goes on), but the three above are common ones that I've seen in "roll your own" logins.

0

I taught to never "roll your own" in situations where there is something already written to do something similar. If I were you I would try to find something thats proven to work and try to build around or on top of that.

1
  • 1
    Yes, that's the plan. However, by combining things from different sources you can never be sure that you do not introduce some kind of vulnerability, right.
    – Michael
    Jul 31, 2014 at 6:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .