Ejemplo n.º 1
0
        public ActionResult Index(UserDetailsModel model)
        {
            UserPrincipal userPrincipal      = null;
            CompanyDTO    objSelectedCompany = null;

            InsiderTradingEncryption.DataSecurity objPwdHash = null;
            string dominName   = string.Empty;
            string adPath      = string.Empty;
            string strError    = string.Empty;
            string s_debugInfo = string.Empty;
            Dictionary <string, object> DictDetails = new Dictionary <string, object>();

            try
            {
                if (!ModelState.IsValid)
                {
                    string formUsername            = model.sUserName;
                    string formPassword            = model.sPassword;
                    string sPasswordHash           = string.Empty;
                    string javascriptEncryptionKey = Common.ConstEnum.Javascript_Encryption_Key;
                    string userPasswordHashSalt    = Common.ConstEnum.User_Password_Encryption_Key;

                    foreach (string key in ConfigurationManager.AppSettings.Keys)
                    {
                        dominName = key.Contains("DirectoryDomain") ? ConfigurationManager.AppSettings[key] : dominName;

                        adPath = key.Contains("DirectoryPath") ? ConfigurationManager.AppSettings[key] : adPath;

                        if (!String.IsNullOrEmpty(dominName) && !String.IsNullOrEmpty(adPath))
                        {
                            if (compilationSection.Debug)
                            {
                                Common.Common.WriteLogToFile("DominName & adPath read successfully ", null);
                            }

                            using (AuthenticateUserModel AuthenticateUserModel = new AuthenticateUserModel())
                            {
                                formUsername = DecryptStringAES(formUsername, javascriptEncryptionKey, javascriptEncryptionKey);
                                formPassword = DecryptStringAES(formPassword, javascriptEncryptionKey, javascriptEncryptionKey);

                                objPwdHash = new InsiderTradingEncryption.DataSecurity();

                                sPasswordHash = objPwdHash.CreateHash(formPassword, userPasswordHashSalt);

                                if (compilationSection.Debug)
                                {
                                    Common.Common.WriteLogToFile("Created Hash successfully ", null);
                                }

                                AuthenticateUserModel.AuthenticateUser(dominName, formUsername, formPassword, adPath, out strError, out DictDetails);
                                {
                                    if (DictDetails.Count != 0)
                                    {
                                        return(this.RedirectAndPost(ConfigurationManager.AppSettings["VigilanteURL"].ToString(), DictDetails));
                                    }
                                    else
                                    {
                                        return(View("AuthenticationFailed"));
                                    }
                                }
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(strError))
                    {
                        //lblError.Text = "Invalid user name or Password!";
                        if (compilationSection.Debug)
                        {
                            Common.Common.WriteLogToFile("Invalid user name or Password!", null);
                        }
                        return(View("AuthenticationFailed"));
                    }
                }
            }
            catch (Exception ex)
            {
                if (compilationSection.Debug)
                {
                    Common.Common.WriteLogToFile("Exception occured in Index method", ex);
                }
                return(View("AuthenticationFailed"));
            }
            finally
            {
            }
            return(null);
        }