Ejemplo n.º 1
0
        public void RegisterMain() // register a new user class
        {
            Checker      checker      = new Checker();
            GetFromFiles getFromFiles = new GetFromFiles("../../json/json.txt");
            int          id           = getFromFiles.GenerateId();

            var username = UsernameAvailableCheck();
            var password = checker.RegisterCheck("Password");


            UserIdentification ui = new UserIdentification();

            ui.username = username;
            ui.password = password;
            ui.id       = id;

            string json = getFromFiles.GetUserJson();

            Users user = JsonConvert.DeserializeObject <Users>(json);

            user.users.Add(ui);

            string editedJson = JsonConvert.SerializeObject(user);

            string       path       = "../../json/json.txt";
            StreamWriter outputFile = new StreamWriter(path);

            outputFile.WriteLine(editedJson);

            outputFile.Flush();

            outputFile.Close();
        }
Ejemplo n.º 2
0
        public bool UsernameCheck(string username) //Checks the JSON file to see if the username already exists
        {
            string gotUsername = "";

            GetFromFiles getFromFiles = new GetFromFiles("../../json/json.txt");
            string       json         = getFromFiles.GetUserJson();

            Users userIdentification = JsonConvert.DeserializeObject <Users>(json);
            var   jsonUsername       = userIdentification.users.Where(x => x.username == username);

            try
            {
                gotUsername = jsonUsername.First().username;
            }
            catch (Exception e)
            {
                gotUsername = null;
            }

            if (gotUsername == null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        public void LogIn() //Log in class
        {
            Checker      checker         = new Checker();
            GetFromFiles getFile         = new GetFromFiles("../../json/json.txt");
            bool         credientalMatch = false;

            var userUsername = checker.RegisterCheck("Username");
            var userPassword = checker.RegisterCheck("Password");

            while (credientalMatch == false)
            {
                credientalMatch = CredientailCheck(userUsername, userPassword, getFile.GetUserJson());
                if (credientalMatch == false)
                {
                    Console.WriteLine("Username or password wrong");
                    LogIn();
                }
            }

            Console.WriteLine("Successful Log in");
        }