views:

76

answers:

2

Do we know the algorithm that asp.net uses to create the authentication cookie (when using forms authentication?)

Can we basically create our own copy implementation? if so, how?

What does it use to generate the encrypted cookie value, I know it uses whatever you pass into the SetAuthCookie call (which is usually the userID/username).

A: 

Let's start with: why? To what purpose are you trying to create the cookie?

Can you create your own authentication features? yes. Can you encrypt your own cookies? yes. Why would you want to completely recreate the forms authentication implementation?

If, for some odd reason, I was bent on doing this I'd start with reflector and rip open the appropriate classes to see how they were coded.

UPDATE

You might check out this article on Java Form-based authentication. And this one which breaks down some of what's available in java vs .net.

Chris Lively
Just want to learn how they do it, and use the same idea for a java application.
Blankman
I like how in .net, the user isn't tied down to a particular user since it isn't using sessionID's.
Blankman
+3  A: 

The forms authentication take uses the membership identifier, a unique value provided by the configured membership provider. It then takes that value, plus any user data set in the ticket turns it into a binary blob, adds an issue date, an expiry date and depending on the configuration either signs it with an HMAC using the machine key, signs and encrypts it with the machine key, or does nothing at all (bad idea!).

It then writes the cookie out as an HTTP only cookie.

Then on each request it loads it in, validates it, uses the membership identifier to lookup the user, and populates the user details on that thread. If sliding ticket expiry is set it will refresh the cookie to have a new expiry date.

blowdart