Beispiel #1
0
        private void AccountRecovery(string username)
        {
            var Encrypt = new encryption();
            var rw      = new ReadAndWrite();

            Console.Clear();

            string encryptedpassword = rw.readEncryptedPassword(username);
            string encryptedrecovery = rw.readEncryptedRecovery(username);

            bool recoverycorrect = false;

            while (!recoverycorrect)
            {
                Console.Write("Please enter the recovery code given to you at account " +
                              "creation: ");

                string recovery = Encrypt.Encrypt(Console.ReadLine());

                if (recovery == encryptedrecovery)
                {
                    Console.WriteLine("Your password is {0}", Encrypt.Decrypt(encryptedpassword));
                    Console.WriteLine("Press enter to return");
                    Console.ReadKey();
                    return;
                }
                else
                {
                    Console.WriteLine("Your recovery code was incorrect");
                    Console.WriteLine("Press enter to try again or S to signup");
                    var response = Console.ReadKey();
                    switch (response.KeyChar)
                    {
                    case 'S':
                    case 's':
                        signup();
                        break;
                    }
                }
            }
            return;
        }
Beispiel #2
0
        public string[] read(string username)
        {
            var Encrypt = new encryption();

            string LoginData64    = File.ReadAllText(username + ".asd");
            var    LoginDataBytes = Convert.FromBase64String(LoginData64);
            string LoginData      = Encoding.UTF8.GetString(LoginDataBytes);

            string[] encrypteddata = LoginData.Split(',');

            string email        = Encrypt.Decrypt(encrypteddata[1]);
            string age          = Encrypt.Decrypt(encrypteddata[2]);
            string password     = Encrypt.Decrypt(encrypteddata[3]);
            string recoverycode = Encrypt.Decrypt(encrypteddata[4]);
            string admin        = Encrypt.Decrypt(encrypteddata[5]);

            string[] data = new string[] { username, email, age, password, recoverycode, admin };

            return(data);
        }
Beispiel #3
0
        public void signup()
        {
            var Encrypt = new encryption();
            var rw      = new ReadAndWrite();

            Console.Clear();

            string username = enterUsername(); //calls enterusernmae - username is returned

            string email = enterEmail();       //calls enteremail - email is returned

            int age = enterAge();              //calls enterage - age is returned

            Console.Write("Password: "******"Your recovery code is {0}, if you have " +
                              "forgoten your password you can use this to retreive your " +
                              "password.", recoverycode);

            bool admin = false;

            if (username == "Plane000_BEN") // sets admin for specified username
            {
                admin = true;
            }

            rw.write(username, email, age, password, recoverycode, admin);

            Console.WriteLine();
            Console.WriteLine("SignUp Succesfull, enter to continue");
            Console.ReadKey();

            start();
        }
Beispiel #4
0
        public void write(string username, string email, int age,
                          string password, int recoverycode, bool admin)
        {
            var Encrypt = new encryption();

            string EncryptedEmail    = Encrypt.Encrypt(email); // encrypts user data
            string EncryptedAge      = Encrypt.Encrypt(Convert.ToString(age));
            string EncryptedPassword = Encrypt.Encrypt(password);
            string EncryptedRecovery = Encrypt.Encrypt(Convert.ToString(recoverycode));
            string EncryptedAdmin    = Encrypt.Encrypt(Convert.ToString(admin));

            string WriteFileString = username + "," + EncryptedEmail + "," + EncryptedAge
                                     + "," + EncryptedPassword + "," + EncryptedRecovery + ","
                                     + EncryptedAdmin; // makes user data one string

            var    WriteFileBytes = Encoding.UTF8.GetBytes(WriteFileString);
            string WriteFile64    = Convert.ToBase64String(WriteFileBytes); // converts to base 64

            File.WriteAllText(username + ".asd", WriteFile64);              // writes to file

            return;
        }
Beispiel #5
0
        public void login()
        {
            var Encrypt = new encryption();
            var rw      = new ReadAndWrite();

            Console.Clear();

            string username = null;
            bool   findfile = false;

            while (findfile == false)
            {
                Console.Write("Username:"******".asd"))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("The user you have entered does not exist");
                    Console.WriteLine("Press enter to try again and S to signup");
                    var response = Console.ReadKey();
                    switch (response.KeyChar)
                    {
                    case 'S':
                    case 's':
                        signup();
                        break;
                    }
                }
            }

            string encryptedpassword = rw.readEncryptedPassword(username);

            bool passwordcorrect = false;

            while (!passwordcorrect)
            {
                Console.Write("Password:"******"The password you have entered is incorrect " +
                                      "press enter to try again and L to log in with a " +
                                      "different user");
                    Console.WriteLine("If you have forgotten your password press " +
                                      "R to recover your account");
                    var response = Console.ReadKey();
                    switch (response.KeyChar)
                    {
                    case 'L':
                    case 'l':
                        login();
                        break;

                    case 'R':
                    case 'r':
                        AccountRecovery(username);
                        break;
                    }
                }
            }
            return;
        }
Beispiel #6
0
        public void loggedIn(string username)
        {
            var Encrypt       = new encryption();
            var Login         = new LogIn();
            var TextAdventure = new Game();
            var GuessRandom   = new GuessRandom();
            var rw            = new ReadAndWrite();

            string[] encrypteddata = rw.readEncrypted(username);
            string[] data          = rw.read(username);
            string   email         = data[1];
            int      age           = int.Parse(data[2]);
            string   password      = data[3];
            bool     admin         = Convert.ToBoolean(data[5]);

            Console.Clear();

            string isadmin = null;

            if (admin)
            {
                isadmin = "you are signed in as an administrator";
            }

            Console.WriteLine("Welcome {0}, {1}", username, isadmin);
            Console.WriteLine();

            Console.WriteLine("You have access to:");
            Console.WriteLine();

            if (admin)
            {
                Console.WriteLine("(0) Admin tools");
            }

            Console.WriteLine("(1) Adventure Game");
            Console.WriteLine("(2) Guess a Random Number Game");
            Console.WriteLine("(3)");
            Console.WriteLine("(4)");
            Console.WriteLine("(5) Reveiw and change your details");
            Console.WriteLine();
            Console.WriteLine("Press enter to logout");

            var response = Console.ReadKey();

            switch (response.KeyChar)
            {
            case '0':
                adminTools(admin, username, encrypteddata);
                break;

            case '1':
                TextAdventure.start();
                break;

            case '2':
                GuessRandom.start();
                break;

            case '3':
                string[] thing = rw.read(username);
                break;

            case '4':
                break;

            case '5':
                userDetails(username);
                break;
            }
            switch (response.Key)
            {
            case ConsoleKey.Enter:
                Login.start();
                return;
            }
            loggedIn(username);
        }
Beispiel #7
0
        private void userDetails(string username)
        {
            var get     = new LogIn();
            var Encrypt = new encryption();
            var rw      = new ReadAndWrite();

            string[] encrypteddata = rw.readEncrypted(username);

            string[] data         = rw.read(username);
            string   email        = data[1];
            int      age          = int.Parse(data[2]);
            string   password     = data[3];
            int      recoverycode = int.Parse(data[4]);
            bool     admin        = Convert.ToBoolean(data[5]);

            Console.Clear();

            Console.WriteLine(username + ", here are your details:");
            Console.WriteLine();

            Console.WriteLine("Email: " + email);
            Console.WriteLine("Age: " + age);
            Console.WriteLine();

            Console.WriteLine("(1) Update email");
            Console.WriteLine("(2) Update age");
            Console.WriteLine("(3) Change password");
            Console.WriteLine();

            Console.WriteLine("Press enter to save and return");

            var response = Console.ReadKey();

            switch (response.KeyChar)
            {
            case '1':
                email = updateEmail(email);
                break;

            case '2':
                age = updateAge(age);
                break;

            case '3':
                password = changePassword(password);
                break;
            }

            rw.write(username, email, age, password, recoverycode, admin);

            loggedIn(username);

            switch (response.Key)
            {
            case ConsoleKey.Enter:
                loggedIn(username);
                break;
            }

            userDetails(username);

            Console.ReadKey();
        }