|
security
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
WinForm user authenticationCan someone point me in the right direction for finding out how to do custom
authentication in a WinForm application? I have a WinForm (VB.Net) application with a login screen. I want my users to input their username and password, then I will authenticate them against my database. That's fine, I can do that. What I can't figure out is how to now tell dotnet that My.User has been authenticated and what roles they are in. I'm converting this from an ASP.Net application, so I've created my own CustomPrincipal class, I'm just missing how to say, "Yes, this user is authenticated" and I can't figure out what to search on to give me any useful information. Help! Diane Hi
You should use the GenericIdentity and GenericPrincipal objects for that. And do associate the current identity to the current thread to be allowed to detect who is calling your methods. Example: class Program { static void Main(string[] args) { IIdentity iden = new GenericIdentity("Claus"); string[] roles = new string[]{"Admin", "Power"}; IPrincipal prin = new GenericPrincipal(iden, roles); System.Threading.Thread.CurrentPrincipal = prin; //call method MyMethod(); Console.WriteLine("Done"); Console.Read(); } static void MyMethod() { //assert caller IIdentity caller = System.Threading.Thread.CurrentPrincipal.Identity; Console.WriteLine("Caller = {0}", caller.Name); } } Show quoteHide quote "Diane Yocom" wrote: > Can someone point me in the right direction for finding out how to do custom > authentication in a WinForm application? > > I have a WinForm (VB.Net) application with a login screen. I want my users > to input their username and password, then I will authenticate them against > my database. That's fine, I can do that. What I can't figure out is how to > now tell dotnet that My.User has been authenticated and what roles they are > in. > > I'm converting this from an ASP.Net application, so I've created my own > CustomPrincipal class, I'm just missing how to say, "Yes, this user is > authenticated" and I can't figure out what to search on to give me any > useful information. > > Help! > Diane > > > Thanks, Claus.
I also found this in the help (finally - was just staring me in the face): ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbcn/html/c47b8c08-3ca9-46c4-b4b0-b06dd2b956f8.htm Show quoteHide quote "Claus Konrad" <ClausKon***@discussions.microsoft.com> wrote in message news:2A628733-A2AA-40CF-9FE8-E35A957C31BE@microsoft.com... > Hi > > You should use the GenericIdentity and GenericPrincipal objects for that. > And do associate the current identity to the current thread to be allowed > to > detect who is calling your methods. > > Example: > > class Program > { > static void Main(string[] args) > { > IIdentity iden = new GenericIdentity("Claus"); > string[] roles = new string[]{"Admin", "Power"}; > IPrincipal prin = new GenericPrincipal(iden, roles); > > System.Threading.Thread.CurrentPrincipal = prin; > > //call method > MyMethod(); > > Console.WriteLine("Done"); > Console.Read(); > } > > > static void MyMethod() > { > //assert caller > IIdentity caller = System.Threading.Thread.CurrentPrincipal.Identity; > Console.WriteLine("Caller = {0}", caller.Name); > > } > } > -- > rgds. > /Claus Konrad > www.clauskonrad.net > > "Diane Yocom" wrote: > >> Can someone point me in the right direction for finding out how to do >> custom >> authentication in a WinForm application? >> >> I have a WinForm (VB.Net) application with a login screen. I want my >> users >> to input their username and password, then I will authenticate them >> against >> my database. That's fine, I can do that. What I can't figure out is how >> to >> now tell dotnet that My.User has been authenticated and what roles they >> are >> in. >> >> I'm converting this from an ASP.Net application, so I've created my own >> CustomPrincipal class, I'm just missing how to say, "Yes, this user is >> authenticated" and I can't figure out what to search on to give me any >> useful information. >> >> Help! >> Diane >> >> >> maybe first of all you should ask yourself why you are building your own
auth/authZ system - Windows provides this for you already... --- Dominick Baier, DevelopMentor http://www.leastprivilege.com Show quoteHide quote > Hi > > You should use the GenericIdentity and GenericPrincipal objects for > that. > And do associate the current identity to the current thread to be > allowed to > detect who is calling your methods. > Example: > > class Program > { > static void Main(string[] args) > { > IIdentity iden = new GenericIdentity("Claus"); > string[] roles = new string[]{"Admin", "Power"}; > IPrincipal prin = new GenericPrincipal(iden, roles); > System.Threading.Thread.CurrentPrincipal = prin; > > //call method > MyMethod(); > Console.WriteLine("Done"); > Console.Read(); > } > static void MyMethod() > { > //assert caller > IIdentity caller = > System.Threading.Thread.CurrentPrincipal.Identity; > Console.WriteLine("Caller = {0}", caller.Name); > } > } > "Diane Yocom" wrote: >> Can someone point me in the right direction for finding out how to do >> custom authentication in a WinForm application? >> >> I have a WinForm (VB.Net) application with a login screen. I want my >> users to input their username and password, then I will authenticate >> them against my database. That's fine, I can do that. What I can't >> figure out is how to now tell dotnet that My.User has been >> authenticated and what roles they are in. >> >> I'm converting this from an ASP.Net application, so I've created my >> own CustomPrincipal class, I'm just missing how to say, "Yes, this >> user is authenticated" and I can't figure out what to search on to >> give me any useful information. >> >> Help! >> Diane Dominick Baier wrote:
> maybe first of all you should ask yourself why you are building your Maybe you want to have custom authentication and not rely on external> own auth/authZ system - Windows provides this for you already... > factors?
X.509 Certificate store - getting - creating certs
SecurityException thrown when serializing custom exception class ActiveDirectory group membership in offline profile Question on the use of CryptoStream How to deploy a VS2005 VB app without signing the clickonce manifest and assy COM+ Security error Credentials Double Hop Seeking Advice on RSA encryption prob How do I determine if a windows identity is authenticated to the network domain |
|||||||||||||||||||||||