Example #1
0
        public ActionResult DatabaseAuthentication(AllModels model)
        {
            string ConnectionString = Server.MapPath("~/DatabaseConnection/ConnectionString.txt");
            string Username         = Server.MapPath("~/DatabaseConnection/Username.txt");
            string Password         = Server.MapPath("~/DatabaseConnection/Password.txt");

            string AdminUser = Server.MapPath("~/DatabaseConnection/AdminUser.txt");
            string AdminPass = Server.MapPath("~/DatabaseConnection/AdminPassword.txt");

            string AdminUserName = System.IO.File.ReadAllText(AdminUser);
            string AdminPassword = System.IO.File.ReadAllText(AdminPass);

            string User2 = EncryptionAndDecryption.Decrypt(AdminUserName);
            string Pass2 = EncryptionAndDecryption.Decrypt(AdminPassword);

            if (model.Maintenance.AdminUser != User2.ToString().TrimEnd() && model.Maintenance.AdminPassword != Pass2.ToString().TrimEnd())
            {
                ViewBag.HeaderError  = string.Format("Unable  to connect to server.");
                ViewBag.MessageError = string.Format("Check your Admin Username or Admin Password.");
                return(View());
            }


            using (StreamWriter sw = System.IO.File.CreateText(ConnectionString))
            {
                sw.WriteLine(model.Maintenance.DatabaseConnection);
            }

            using (StreamWriter sw = System.IO.File.CreateText(Username))
            {
                sw.WriteLine(EncryptionAndDecryption.Encrypt(model.Maintenance.DatabaseUser));
            }

            using (StreamWriter sw = System.IO.File.CreateText(Password))
            {
                sw.WriteLine(EncryptionAndDecryption.Encrypt(model.Maintenance.DatabasePassword));
            }

            DBConnection();

            using (SqlConnection connection = new SqlConnection(con))
            {
                try
                {
                    connection.Open();
                }
                catch
                {
                    ViewBag.HeaderError  = string.Format("Unable  to connect to server.");
                    ViewBag.MessageError = string.Format("Check your server connection.");
                    return(View());
                }
            }

            ViewBag.HeaderSuccess  = string.Format("Connection Success.");
            ViewBag.MessageSuccess = string.Format("Your Connection Server has connected.");
            return(View());
        }
Example #2
0
        public string DBConnection()
        {
            DatabaseConnectionClass databaseConnectionClass = new DatabaseConnectionClass();
            string Con                = databaseConnectionClass.var1;
            string User               = databaseConnectionClass.var2;
            string Pass               = databaseConnectionClass.var3;
            string Connectionstring   = System.IO.File.ReadAllText(Con);
            string ConnectionUserName = System.IO.File.ReadAllText(User);
            string ConnectionPasswrod = System.IO.File.ReadAllText(Pass);

            string Con1  = Connectionstring.TrimEnd();
            string User1 = EncryptionAndDecryption.Decrypt(ConnectionUserName);
            string Pass1 = EncryptionAndDecryption.Decrypt(ConnectionPasswrod);

            con  = "Data Source=" + Con1.ToString() + ";Initial Catalog=DB_CORE;Network Library=DBMSSOCN;User ID=" + User1.ToString() + "; Password="******"";
            con2 = "Data Source=" + Con1.ToString() + ";Initial Catalog=DB_CENTRAL;Network Library=DBMSSOCN;User ID=" + User1.ToString() + "; Password="******"";
            con3 = "Data Source=" + Con1.ToString() + ";Initial Catalog=DB_INVENTORY;Network Library=DBMSSOCN;User ID=" + User1.ToString() + "; Password="******"";

            return(con);
        }
Example #3
0
        public ActionResult LoginDatabase(AllModels model)
        {
            string AdminUser = Server.MapPath("~/DatabaseConnection/AdminUser.txt");
            string AdminPass = Server.MapPath("~/DatabaseConnection/AdminPassword.txt");

            string AdminUserName = System.IO.File.ReadAllText(AdminUser);
            string AdminPassword = System.IO.File.ReadAllText(AdminPass);

            string User2 = EncryptionAndDecryption.Decrypt(AdminUserName);
            string Pass2 = EncryptionAndDecryption.Decrypt(AdminPassword);

            if (model.Maintenance.AdminUser != User2.ToString().TrimEnd() || model.Maintenance.AdminPassword != Pass2.ToString().TrimEnd())
            {
                ViewBag.HeaderError  = string.Format("Unable  to connect to server.");
                ViewBag.MessageError = string.Format("Check your Admin Username or Admin Password.");
                return(View());
            }
            else
            {
                Session["AdminUser"] = User2;
                return(RedirectToAction("UpdateData", "Login"));
            }
        }