Form Authentication Ticket

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Form Authentication Ticket

    I've read some books and online articles on how to implement form
    authentication. Some taught me just to do
    FormsAuthentication.RedirectFromLoginPage(username .Value, false) after the
    user is validated. While others include more steps, like generating
    authentication ticket, encrypt it, create a cookie, and add it to the
    response, before redirecting the user. Both way should work, but why do I
    need to generate an authentication ticket, when it still works if I don't
    generate one?

    What's an authentication ticket for? Why do I need it?

    Thank you.
    wrytat Guest

  2. Similar Questions and Discussions

    1. Forms Authentication Ticket Reissue
      When using Forms Authentication with the SlidingExpiration attribute set to 'true', the authentication ticket is reissued sometime after half of...
    2. Encryption of Authentication Ticket
      i have a question regarding the encryption of an Authentication Ticket under FormsAuthentication. Can anyone tell me what type of encryption is used...
    3. Why authentication Ticket expires
      Can anybody tells if I'm doing something wrong in this code and why the user authentication ticket always expires 30 minutes later, even though I...
    4. Authentication ticket, cookieless, forms authentication?
      Hi. I want to use Forms Authentication, cookieless. The issue is setting the Authentication Ticket without using cookies (!) That is, the...
    5. Custom Authentication Ticket
      James, I found your C code and tutorial about this. I attempted to convert it to VB as follows but could you possibly tell me why the code segment...
  3. #2

    Default Re: Form Authentication Ticket

    The auth ticket is in essence the user's name encrypted in the cookie. This
    is how ASP.NET knows who the user is when the browser makes requests into
    your app. For simplicity, I'd suggest not messing with it. The only time
    you'd want to do something with the Ticket/Cookie is if you wanted to put
    other sensitive data into a cookie so the browser passes it back every time.
    Usually since it's putting the username then all other sensitive data can
    be fetched from the database on the server, meaning there's no need to put
    anything else into the cookie.

    -Brock
    DevelopMentor
    [url]http://staff.develop.com/ballen[/url]


    > I've read some books and online articles on how to implement form
    > authentication. Some taught me just to do
    > FormsAuthentication.RedirectFromLoginPage(username .Value, false) after
    > the user is validated. While others include more steps, like
    > generating authentication ticket, encrypt it, create a cookie, and add
    > it to the response, before redirecting the user. Both way should work,
    > but why do I need to generate an authentication ticket, when it still
    > works if I don't generate one?
    >
    > What's an authentication ticket for? Why do I need it?
    >
    > Thank you.
    >


    Brock Allen Guest

  4. #3

    Default Re: Form Authentication Ticket

    Does that mean if I am only going to need the cookie to store the user name,
    I just need to do a FormsAuthentication.RedirectFromLoginPage(username .Value,
    false) or FormsAuthentication.SetAuthCookie and Response.Redirect(somewhere,
    True) after validation? But if I need to store other data in the same cookie,
    I have to do something like this:

    Dim tkt As FormsAuthenticationTicket
    Dim cookiestr As String
    Dim ck As HttpCookie

    tkt = New FormsAuthenticationTicket(1, txtUserName.Value, DateTime.Now(),
    dateTime.Now.AddMinutes(30), false, "other data")
    cookiestr = FormsAuthentication.Encrypt(tkt)
    ck = new HttpCookie(FormsAuthentication.FormsCookieName(), cookiestr)
    ck.Path = FormsAuthentication.FormsCookiePath()
    Response.Cookies.Add(ck)
    Response.Redirect(somewhere,True)

    Am I right?

    Then if I need to store more than 1 data do I just do:
    tkt = New FormsAuthenticationTicket(1, txtUserName.Value, DateTime.Now(),
    dateTime.Now.AddMinutes(30), false, "data1", "data2", "data3", ..., "dataN") ?

    And how do I retrieve the data?

    Sorry, a lot of questions...

    "Brock Allen" wrote:
    > The auth ticket is in essence the user's name encrypted in the cookie. This
    > is how ASP.NET knows who the user is when the browser makes requests into
    > your app. For simplicity, I'd suggest not messing with it. The only time
    > you'd want to do something with the Ticket/Cookie is if you wanted to put
    > other sensitive data into a cookie so the browser passes it back every time.
    > Usually since it's putting the username then all other sensitive data can
    > be fetched from the database on the server, meaning there's no need to put
    > anything else into the cookie.
    >
    > -Brock
    > DevelopMentor
    > [url]http://staff.develop.com/ballen[/url]
    >
    >
    >
    > > I've read some books and online articles on how to implement form
    > > authentication. Some taught me just to do
    > > FormsAuthentication.RedirectFromLoginPage(username .Value, false) after
    > > the user is validated. While others include more steps, like
    > > generating authentication ticket, encrypt it, create a cookie, and add
    > > it to the response, before redirecting the user. Both way should work,
    > > but why do I need to generate an authentication ticket, when it still
    > > works if I don't generate one?
    > >
    > > What's an authentication ticket for? Why do I need it?
    > >
    > > Thank you.
    > >
    >
    >
    >
    >
    wrytat Guest

  5. #4

    Default Re: Form Authentication Ticket

    For your first question, it's basically right your approach, though I would
    recommend not to depend on harcoded values but to use the configured in
    Forms settings.
    Take a look at this sample:

    [url]http://weblogs.asp.net/hernandl/archive/2004/07/30/FormsAuthRolesRev.aspx[/url]

    For your second question, the way to add more data to your ticket is simply
    storing a single string with all the information in there. In that case you
    shoud be aware of your string lenght because of the limitation of the cookie
    size.
    Notice that the above link give you an advice on this issue. You may take a
    look at this link as well:

    [url]http://weblogs.asp.net/hernandl/archive/2004/08/05/FormsAuthRoles2.aspx[/url]

    Regards,
    Hernan de Lahitte.
    [url]http://clariusconsulting.net/hdl[/url]


    "wrytat" <wrytat@discussions.microsoft.com> wrote in message
    news:F8669715-7FA4-45D8-A68B-65F24FB4AFF8@microsoft.com...
    > Does that mean if I am only going to need the cookie to store the user
    > name,
    > I just need to do a
    > FormsAuthentication.RedirectFromLoginPage(username .Value,
    > false) or FormsAuthentication.SetAuthCookie and
    > Response.Redirect(somewhere,
    > True) after validation? But if I need to store other data in the same
    > cookie,
    > I have to do something like this:
    >
    > Dim tkt As FormsAuthenticationTicket
    > Dim cookiestr As String
    > Dim ck As HttpCookie
    >
    > tkt = New FormsAuthenticationTicket(1, txtUserName.Value, DateTime.Now(),
    > dateTime.Now.AddMinutes(30), false, "other data")
    > cookiestr = FormsAuthentication.Encrypt(tkt)
    > ck = new HttpCookie(FormsAuthentication.FormsCookieName(), cookiestr)
    > ck.Path = FormsAuthentication.FormsCookiePath()
    > Response.Cookies.Add(ck)
    > Response.Redirect(somewhere,True)
    >
    > Am I right?
    >
    > Then if I need to store more than 1 data do I just do:
    > tkt = New FormsAuthenticationTicket(1, txtUserName.Value, DateTime.Now(),
    > dateTime.Now.AddMinutes(30), false, "data1", "data2", "data3", ...,
    > "dataN") ?
    >
    > And how do I retrieve the data?
    >
    > Sorry, a lot of questions...
    >
    > "Brock Allen" wrote:
    >
    >> The auth ticket is in essence the user's name encrypted in the cookie.
    >> This
    >> is how ASP.NET knows who the user is when the browser makes requests into
    >> your app. For simplicity, I'd suggest not messing with it. The only time
    >> you'd want to do something with the Ticket/Cookie is if you wanted to put
    >> other sensitive data into a cookie so the browser passes it back every
    >> time.
    >> Usually since it's putting the username then all other sensitive data can
    >> be fetched from the database on the server, meaning there's no need to
    >> put
    >> anything else into the cookie.
    >>
    >> -Brock
    >> DevelopMentor
    >> [url]http://staff.develop.com/ballen[/url]
    >>
    >>
    >>
    >> > I've read some books and online articles on how to implement form
    >> > authentication. Some taught me just to do
    >> > FormsAuthentication.RedirectFromLoginPage(username .Value, false) after
    >> > the user is validated. While others include more steps, like
    >> > generating authentication ticket, encrypt it, create a cookie, and add
    >> > it to the response, before redirecting the user. Both way should work,
    >> > but why do I need to generate an authentication ticket, when it still
    >> > works if I don't generate one?
    >> >
    >> > What's an authentication ticket for? Why do I need it?
    >> >
    >> > Thank you.
    >> >
    >>
    >>
    >>
    >>

    Hernan de Lahitte Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139