This solution demonstrates creating a login dialog box to authenticate users and restrict access to features in an application. The user must first log in, within 3 attempts, either using custom authentication or Windows Authentication. After the user logs in, the role membership is checked to see if the user is a "Manager" or a Windows Administrator. If so, the Main form displays a list of the users in the XML file, otherwise the Main form is left blank.
A Windows Principal object is used to determine if the user logged into Windows is an Administrator.
A Generic Principal object is used to determine if a user is a member of the "Manager" role.
An XML file is loaded into a DataSet and searched for an appropriate match
A DataGrid on the Main form is anchored so that it resizes as the form resizes.
If the user logs in as an Administrator or Manager (Account named: Bob) the
current list of users and passwords is made available to the user.
If the user logs on with the account named John the user is not able to view
this information.
Requirements:
Microsoft Visual Studio.NET Professional or greater.
Windows 2000 or Windows XP
Running the Sample:
Simply press F5.
The Users.Xml file is stored in the bin directory and is used to store the user
accounts.
The XML is file is not encrypted for simplicity. Encryption should be
used to protect the passwords when someone opens the XML file.
There are 2 user accounts:
Name | Password | Role |
Bob | pass | Manager |
John | pass | Sales |
See Also
Creating Windows Principal and Windows Identity objects. Creating Generic Principal and Generic Identity Objects