Ejemplo n.º 1
0
        private Dictionary <string, string> ProcessAll()
        {
            const string key   = "Key";
            const string value = "Value";

            DataTable dataTable = ReadAll();
            string    password  = Password();

            Dictionary <string, string> appSettings = new Dictionary <string, string>();

            for (int Row = 0; Row < dataTable.Rows.Count; Row++)
            {
                appSettings.Add(Convert.ToString(dataTable.Rows[Row][key]), _cryptographicProvider.Decrypt(Convert.ToString(dataTable.Rows[Row][value]), password));
            }

            return(appSettings);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //setup Dependency Injection
            ServiceProvider diServiceProvider = new ServiceCollection()
                                                .AddSingleton <ILoggerFactory, LoggerFactory>()
                                                .AddLogging(bldr =>
            {
                bldr.AddConsole();
            })
                                                //add program specific implementations for interfaces
                                                .AddSingleton <ICryptographicProvider, AESProvider>()
                                                .BuildServiceProvider();

            ILogger logger = diServiceProvider.GetService <ILoggerFactory>().CreateLogger <Program>();

            try
            {
                Console.WriteLine("Please Log In");
                Console.WriteLine("-----------------");
                Console.Write("Username: "******"Password: "******"Validation against live database...\r\n");

                using (FinanceContext context = new FinanceContext())
                {
                    //var hash = HashManager.GetHash(secPassword);
                    //context.Add(new User() { UserName = userName, Password = hash });
                    //context.SaveChanges();

                    var foundUser = context.User.Where(u => u.UserName == userName).FirstOrDefault();
                    if (foundUser != null)
                    {
                        if (HashManager.Match(secPassword, foundUser.Password))
                        {
                            logger.LogInformation($"user: {userName} authenticated...\r\n");

                            ICryptographicProvider provider = diServiceProvider.GetService <ICryptographicProvider>();
                            provider.Inititalize(secPassword);

                            var encrypted = provider.Encrypt("this is a test");
                            Console.WriteLine(encrypted);
                            Console.WriteLine();
                            var decrypted = provider.Decrypt(encrypted);
                            Console.WriteLine(decrypted);
                        }
                        else
                        {
                            logger.LogInformation("incorrect password provided...\r\n");
                            Console.WriteLine("invalid user/pass.");
                        }
                    }
                    else
                    {
                        logger.LogInformation("user not found...\r\n");
                        Console.WriteLine("invalid user/pass.");
                    }
                }//end using
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Error occured...\r\n");
            }
        }