Reputation: 89
I'm contemplating how I should implement authorization and authentication with ASP.NET and MVC2. Lets refer to this as a user system.
I have seen three types of solutions in the wild:
I've been reading your knowing thoughts and many say that trying to roll your own "user system" might be even dangerous, if you are not careful with the security details. On the other hand, the solution is a whole lot simpler. Everything is probably stored in one database and user specific stuff is in one users table. The overhead for this solution seems to be quite low.
Using the ASP.NET membership solution allows to use a lot of out-of-the-box functionality, but IMHO, is really confusing. You probably need to store the membership stuff in its own database and somehow be able to link the user entity from your site specific database to the ASP.NET one.
If you are using the ASP.NET membership
If you have rolled your own
I'm really paralyzed by analyzing these possibilities. Please kick me in the right direction from this sticky web of membership paralysis! Thank you.
Upvotes: 4
Views: 538
Reputation: 63905
Many people choose not to roll their own authentication systems for good reason! It's quite dangerous and there are many small ways you can get it wrong and leave your site open to attack.
I, however, am one of those risk takers and did roll my own. I double and triple checked every line of code for a security flaw and so far I've not had any security flaws patched since I released 1.0 of my authentication system. Anyway, my authentication system is named FSCAuth and BSD licensed.
I'm not quite sure what you mean. I basically have one layer where user data is retrieved and written to/from the database. One layer where FSCAuth actually deals with the cookies and HTTP authentication. And, one layer where you tell FSCAuth that "hey, this page should only be seen if the current user is in the Admin group".
My UserData class is quite simple with only 4 fields being required: Username, PasswordHash, UniqueID, and Salt. This is what FSCAuth depends on. If you need more fields, you can inherit form the UserData class and it'll work just the same.
I found so many short comings in the built in ASP.Net authentication
Many of these problems are by design and I believe are a symptom of trying to make one piece of software that will satisfy everyone.
Well, in FSCAuth I left quite a bit of things out by design, and honestly there is no way it's suitable for everyone.. but it's much easier to use than ASP.Net membership in many common scenarios. Can use just about any hashing algorithm under the sun. A single database hit for authentication. Stateless logins. A unique ID can be anything that'll fit in a string. Etc.
So if you're stuck in the decision between working around ASP.Net's built-in authentication and rolling your own, give FSCAuth a look first. If nothing else, it makes a great starting point for rolling your own.
Upvotes: 0
Reputation: 47417
the built in membership provider is already secure and is really REALLY easy to use. You can be up and running with built in membership in a couple of hours. Alternatively (depending on what type of application you're building) you could also check out using OpenID which is what StackOverflow uses.
Also, with the built in Membership Provider, creating relationships is as easy as using a "uniqueidentifier" to relate the aspnet_User table (I can't remember the exact name off the top of my head) with the related table.
I store all of my membership "stuff" in the same database as the system db, and it has never steered me wrong. Creating the membership "stuff" is easy as well. Just run the aspnet_regsql.exe against the database that you want to have asp.net membership
Here's another SO question along the same lines.
Upvotes: 1