Ask a Question related to ASP.NET Security, Design and Development.
-
A. Elamiri #1
Cache Dependent Key/Encryption
I would like to store some Role Information in a cookie since I cannot use
Session in the AuthenticateRequest method.
I thought of encrypting the cookie using Rijndael Algo. for provider. I
would generate a 16 character key store it as a Cached object and replace it
every 20-30 minutes, if the cookie data does not decrypt then simply reload
it because I would assume that key expired.
Is this a secure way of doing it?
A. Elamiri Guest
-
Image dependent on DB value.
I've got a datagrid and one of the columns shows whether a row has been selected. If it's selected the row background color is grey and one of the... -
Dependent Dropdowns
I have searched high and low and haven't found a good tutorial for doing dependent dropdowns. I have 2 tables in my DB, Cat and SubCat, Cat... -
Dependent DropDownLists
I am having a problem with my datagrid. I have 2 edit columns containing DropDownLists, one dependent on another. Both lists are being populated... -
PUT dependent files?
Hi there, I have clicked the option to also include the dependent files a files I want to put to the testing server. How do I un-check this... -
Move dependent files
When uploading via dreamweaver I accidentally checked the "Don't Ask Me Again" checkbox, how can I undo this so I DO get prompted to upload dependent... -
Hernan de Lahitte #2
Re: Cache Dependent Key/Encryption
Perhaps you might use the Forms Authentication cookie/ticket management that
is very similar that the one you 'd described but you don't need to warry
about keymanagement and expiration issues. You have an example of this here:
On your login page after the validation step, you get the roles info
(string[] roles) and create/encrypt the cookie like this:
HttpCookie cookie = FormsAuthentication.GetAuthCookie( UserId.Text, false );
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(
cookie.Value );
// Store roles inside the Forms cookie.
FormsAuthenticationTicket newticket = new FormsAuthenticationTicket(
ticket.Version,
ticket.Name,
ticket.IssueDate,
ticket.Expiration,
ticket.IsPersistent,
String.Join( "|", roles),
ticket.CookiePath);
cookie.Value = FormsAuthentication.Encrypt(newticket);
Context.Response.Cookies.Set(cookie);
Response.Redirect( FormsAuthentication.GetRedirectUrl( newticket.Name,
newticket.IsPersistent ) );
On the Application_AuthenticateRequest you put this code to load you
Principal object.
if (Context.Request.IsAuthenticated)
{
// retrieve user's identity from httpcontext user
FormsIdentity ident = (FormsIdentity)Context.User.Identity;
// retrieve roles from the authentication ticket userdata field
string[] arrRoles = ident.Ticket.UserData.Split(new char[] {'|'});
// create principal and attach to user
Context.User = new System.Security.Principal.GenericPrincipal(ident,
arrRoles);
}
I hope this help.
Regards,
Hernan de Lahitte
Lagash Systems S.A.
[url]http://weblogs.asp.net/hernandl[/url]
This posting is provided "AS IS" with no warranties, and confers no rights.
"A. Elamiri" <abdellahDOTelamiriATclintonDOTedutNOSPAM> wrote in message
news:um7sEnhJEHA.3728@TK2MSFTNGP12.phx.gbl...it> I would like to store some Role Information in a cookie since I cannot use
> Session in the AuthenticateRequest method.
>
> I thought of encrypting the cookie using Rijndael Algo. for provider. I
> would generate a 16 character key store it as a Cached object and replacereload> every 20-30 minutes, if the cookie data does not decrypt then simply> it because I would assume that key expired.
>
> Is this a secure way of doing it?
>
>
Hernan de Lahitte Guest
-
A. Elamiri #3
Re: Cache Dependent Key/Encryption
Thanks!! I'll try that out
--
Abdellah Elamiri
..net Developer
Efficacy through simplicity
"Hernan de Lahitte" <hernan@lagash.com> wrote in message
news:OkIeEAkJEHA.2456@TK2MSFTNGP12.phx.gbl...that> Perhaps you might use the Forms Authentication cookie/ticket managementhere:> is very similar that the one you 'd described but you don't need to warry
> about keymanagement and expiration issues. You have an example of thisfalse );>
> On your login page after the validation step, you get the roles info
> (string[] roles) and create/encrypt the cookie like this:
>
> HttpCookie cookie = FormsAuthentication.GetAuthCookie( UserId.Text,rights.> FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(
> cookie.Value );
>
> // Store roles inside the Forms cookie.
> FormsAuthenticationTicket newticket = new FormsAuthenticationTicket(
> ticket.Version,
> ticket.Name,
> ticket.IssueDate,
> ticket.Expiration,
> ticket.IsPersistent,
> String.Join( "|", roles),
> ticket.CookiePath);
>
> cookie.Value = FormsAuthentication.Encrypt(newticket);
> Context.Response.Cookies.Set(cookie);
> Response.Redirect( FormsAuthentication.GetRedirectUrl( newticket.Name,
> newticket.IsPersistent ) );
>
> On the Application_AuthenticateRequest you put this code to load you
> Principal object.
>
> if (Context.Request.IsAuthenticated)
> {
> // retrieve user's identity from httpcontext user
> FormsIdentity ident = (FormsIdentity)Context.User.Identity;
> // retrieve roles from the authentication ticket userdata field
> string[] arrRoles = ident.Ticket.UserData.Split(new char[] {'|'});
> // create principal and attach to user
> Context.User = new System.Security.Principal.GenericPrincipal(ident,
> arrRoles);
> }
>
> I hope this help.
>
> Regards,
>
> Hernan de Lahitte
> Lagash Systems S.A.
> [url]http://weblogs.asp.net/hernandl[/url]
>
>
> This posting is provided "AS IS" with no warranties, and confers nouse>
> "A. Elamiri" <abdellahDOTelamiriATclintonDOTedutNOSPAM> wrote in message
> news:um7sEnhJEHA.3728@TK2MSFTNGP12.phx.gbl...> > I would like to store some Role Information in a cookie since I cannotreplace> > Session in the AuthenticateRequest method.
> >
> > I thought of encrypting the cookie using Rijndael Algo. for provider. I
> > would generate a 16 character key store it as a Cached object and> it> reload> > every 20-30 minutes, if the cookie data does not decrypt then simply>> > it because I would assume that key expired.
> >
> > Is this a secure way of doing it?
> >
> >
>
A. Elamiri Guest



Reply With Quote

