Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Security / March 2007

Tip: Looking for answers? Try searching our database.

Windows authendicate

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Johnny E. Jensen - 09 Mar 2007 18:34 GMT
Hey

I'am writing a Windows application using C#. I would like to do this:

Application Start:
   Is User Authendicated (windows)
   does user exists in Administrators or in MyAppGroup ( MyAppGroup = the
AD group for users running the application)

If IsUser Authendicated  = False or not in the above groups -> display login
form

I found some code:
System.Security.Principal.WindowsIdentity ident =
System.Security.Principal.WindowsIdentity.GetCurrent();

System.Security.Principal.WindowsPrincipal prin = new
WindowsPrincipal(ident);

System.Threading.Thread.CurrentPrincipal = prin;

IdentityReferenceCollection col = ident.Groups;

IdentityReference ir = col[1];

In the ident object i'll get the IsAuthendicated property and also i see the
Groups property

The two last lines was just to have a look on a group. I cant get the group
name (like Administrator) how to do that?

Kind regards
Johnny E. Jensen
<ct> - 17 Mar 2007 15:19 GMT
Try this,

WindowsIdentity ident = WindowsIdentity.GetCurrent();
WindowsPrincipal prin = new WindowsPrincipal(ident);

// User authenticated?
if (ident.IsAuthenticated)
{
   // User is administrator or in MyAppGroup?
   if (!prin.IsInRole("Administrator") && !prin.IsInRole("MyAppGroup"))
   {
       // Show login form
   }
}
else
{
    // Show login form
}

Signature

Carsten Thomsen
Senior .NET Solutions Architect / Developer / Author
MCAD/MCSD/MCSE/MCTS

> Hey
>
[quoted text clipped - 29 lines]
> Kind regards
> Johnny E. Jensen

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.