Role-based SecurityThe Microsoft .NET environment now offers an excellent alternative to Java in producing portable and secure code. It uses a role-based approach for user authentication, with the WindowsIndentity class, where the GetCurrent() method can be used to get the current user. The WindowsPrincipal class can then be used to apply the role. The results are then:
|
Code used
public void rolebased() { WindowsIdentity myID = WindowsIdentity.GetCurrent(); hash1= myID.Name; hash2= myID.AuthenticationType; WindowsPrincipal myPrin = new WindowsPrincipal(myID); if (myPrin.IsInRole(WindowsBuiltInRole.Administrator)) hash3="You're an Administrator "; else hash3="You're not an Administrator"; }