Example #1
0
        static void Login(HashWorker worker, byte[] salt)
        {
            Console.WriteLine("Please enter your username...\n");
            string username = Console.ReadLine();

            Console.WriteLine("Please enter your password...\n");
            string password = Console.ReadLine();

            Console.WriteLine("Working...");

            byte[] hashedPW = worker.ComputeIteratedHash(password, salt);

            password = Convert.ToBase64String(hashedPW);

            User u;

            using (UserStorage us = new UserStorage())
            {
                u = us.GetByPassword(password);
            }

            if (u is null)
            {
                attempts++;
                Console.WriteLine("Invalid credentials...");
                return;
            }

            Console.WriteLine(u.ToString());
            attempts = 0;
        }
Example #2
0
        static void CreateUser(HashWorker worker, byte[] salt)
        {
            Console.WriteLine("Please enter the username to be stored...\n");
            string username = Console.ReadLine();

            Console.WriteLine("Please enter the password to be encrypted...\n");
            string password = Console.ReadLine();

            Console.WriteLine("Working...");

            byte[] hashedPW = worker.ComputeIteratedHash(password, salt);

            password = Convert.ToBase64String(hashedPW);

            using (UserStorage us = new UserStorage())
            {
                us.Create(new User {
                    Username = username, Password = password
                });
            }
        }