WPF C#-multiple user privileges

725 views Asked by At

I want to display different menu for different users using c# wpf.

Also I already have multiple login only with oracle database.

I want to control user privileges through C#.

1

There are 1 answers

0
Thiago Avelino On

Aravindhan – First you need to have in place the Authentication and Authorization process in place. So, how you do the authentication:

http://blog.magnusmontin.net/2013/03/24/custom-authorization-in-wpf/

Basically, you need to implement the interfaces described on the link above that .Net provides to you. When you get on the IAuthenticationService ->AuthenticateUser method, you will have to provide the Oracle implementation for that.

The implementation will be similar to the snippet below:

public User AuthenticateUser(string username, string clearTextPassword){
        var List<InternalUserData> _users = GetUsersList();
            InternalUserData userData = _users.FirstOrDefault(u => u.Username.Equals(username) 
                && u.HashedPassword.Equals(CalculateHash(clearTextPassword, u.Username)));
            if (userData == null)
                throw new UnauthorizedAccessException("Access denied. Please provide some valid credentials.");

            return new User(userData.Username, userData.Email, userData.Roles);
        }

Public List<InternalUserData> GetUsersList(){
   string sql = "SELECT Username, Email, Password, Userole FROM USER"; 
    command.CommandText = sql; 
 var List< InternalUserData> listUsers = new List< InternalUserData>();
    OracleDataReader reader = command.ExecuteReader(); 
    while (reader.Read()) 
    {
listUsers.Add( new InternalUserData((string)reader["Username"], (string)reader["Email"], (string)reader["Password"],new string[] { (string)reader["Userole "]})
    }
return listUsers;

}