private static User GetUser(ClientHandler clientHandler)
 {
     User u = AuthUsers
         .Where(client => client.Value == clientHandler)
         .Select(user => user.Key).FirstOrDefault();
     return u;
 }
 public static void TryDeAuthenticate(ClientHandler clientHandler)
 {
     var user = GetUser(clientHandler);
     if (user != null)
     {
         DeAuthenticate(user.Username);
     }
 }
        public static Boolean Authenticate(String username, String passhash, ClientHandler clientHandler)
        {
            //check that user and passhash are valid.  
            var user = Datastorage.Instance.GetUser(username);

            // if the user is null, there is no user found. 
            // => return false (authentication failed).
            if (user == null)  return false;
            // if the password is not equals to the passhash, 
            // the password is incorrect. => return false (auth failed).
            if (user.Password != passhash) return false;

            // Check if user was already in the list.
            var result = AuthUsers.Keys.FirstOrDefault(u => u.Username == user.Username);
            if (result != null)
            {
                return false;
            }
            AuthUsers.GetOrAdd(user, clientHandler);
            return true;
        }