Exemplo n.º 1
0
 void sSink_OnAuthentication(object sender, AuthenticationEventArgs e)
 {
     if (OnAuthentication != null)
     {
         OnAuthentication(sender, e);
     }
 }
        public void Authenticate(ClientConnectionInfo cci, string encryptedCustomerID, string encryptedExtensionNumber, string encryptedPassword)
        {
            string userKey = encryptedCustomerID + " " + encryptedExtensionNumber + " " + encryptedPassword;

            if (IsAuthenticated(userKey) == false)
            {
                RijndaelHelper h = new RijndaelHelper(System.Text.Encoding.ASCII.GetString(cci.Provider.Key));

                int customerID = Convert.ToInt32(h.Decrypt(encryptedCustomerID));
                int extensionNumber = Convert.ToInt32(h.Decrypt(encryptedExtensionNumber));
                string password = h.Decrypt(encryptedPassword);

                if (OnAuthentication != null)
                {
                    AuthenticationEventArgs args = new AuthenticationEventArgs(customerID, extensionNumber, password);
                    OnAuthentication(this, args);

                    if (args.IsAuthenticated == false)
                    {
                        throw new Exception("Failed to authenticate");
                    }
                    else
                    {
                        lock (AuthUsers.SyncRoot)
                        {
                            AuthUsers.Add(userKey, DateTime.Now);
                        }
                    }
                }
                else
                {
                    throw new Exception("Failed to authenticate");
                }
            }
        }