Beispiel #1
0
        public static void Main(string[] args)
        {
            // Check if we have a database
            options.LoadOptions();
            db = new SQLiteConnection(Environment.CurrentDirectory + "/database.sqlite");

            db.CreateTable <User>();
            db.CreateTable <LoginSession>();
            db.CreateTable <Item>();
            db.CreateTable <ItemStock>();
            db.CreateTable <Customer>();
            db.CreateTable <Contract>();
            db.CreateTable <Invoice>();
            db.CreateTable <Cart>();
            db.CreateTable <Cashier>();
            db.CreateTable <CashierSession>();

            // Check if there is atleast 1 user
            if (db.Query <User>("SELECT * FROM User WHERE 1;").Count == 0)
            {
                Random rnd = new Random();
                // Seems like there are no users, let's make a default admin/admin
                const string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                string       pass  = new string(Enumerable.Repeat(chars, 8).Select(s => s[rnd.Next(s.Length)]).ToArray());
                User         u     = new User();
                HashSalt     hs    = Utilities.GenerateSaltedHash(64, pass);

                u.displayName = "Admin";
                u.username    = "******";
                u.pinCode     = rnd.Next(0, 9999).ToString();
                u.Hash        = hs.Hash;
                u.Salt        = hs.Salt;
                u.isAdmin     = true;

                db.Insert(u);

                Console.Write("\nWARNING! No user was found! Initial admin user created, you can now login with the following credentials: \n\n\tUsername: "******"admin");
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("\tPassword: "******"\tPincode: ");
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine(u.pinCode);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\n\n\t!!! It's recommended to change this ASAP !!!\n\n");
                Console.ForegroundColor = ConsoleColor.White;

                Thread.Sleep(500);
            }

            CreateHostBuilder(args).Build().Run();
        }
Beispiel #2
0
        public static HashSalt GenerateSaltedHash(int size, string password)
        {
            var saltBytes = new byte[size];
            var provider  = new RNGCryptoServiceProvider();

            provider.GetNonZeroBytes(saltBytes);
            var salt = Convert.ToBase64String(saltBytes);

            var rfc2898DeriveBytes = new Rfc2898DeriveBytes(password, saltBytes, 10000);
            var hashPassword       = Convert.ToBase64String(rfc2898DeriveBytes.GetBytes(256));

            HashSalt hashSalt = new HashSalt {
                Hash = hashPassword, Salt = salt
            };

            return(hashSalt);
        }