コード例 #1
0
        private void AddAccountData(string[] userData)
        {
            Console.WriteLine("If you want to save your nickname and password to the device, click Enter");
            var key = Console.ReadKey(true);

            if (key.Key == ConsoleKey.Enter)
            {
                userNicknamesAndPasswords = fileMaster.ReadDataToUser(FilePath);
                UserNicknameAndPassword userNicknameAndPassword = new UserNicknameAndPassword(userData[0], userData[1]);
                if (userNicknamesAndPasswords.Count() != 0)
                {
                    foreach (var oneUserNicknameAndPassword in userNicknamesAndPasswords)
                    {
                        if (oneUserNicknameAndPassword.Nickname == userNicknameAndPassword.Nickname &&
                            oneUserNicknameAndPassword.Password == userNicknameAndPassword.Password)
                        {
                            Console.WriteLine("You have this nickname and password");
                            return;
                        }
                        else if (oneUserNicknameAndPassword.Nickname == userNicknameAndPassword.Nickname &&
                                 oneUserNicknameAndPassword.Password != userNicknameAndPassword.Password)
                        {
                            Console.WriteLine("You have this nickname but have another password,\n\r" +
                                              "If you want to change data, click 'Enter'");
                            var chackRewrite = Console.ReadKey(true);
                            if (chackRewrite.Key == ConsoleKey.Enter)
                            {
                                RewriteDate();
                            }
                            return;
                        }
                    }
                }
                void RewriteDate()
                {
                    userNicknamesAndPasswords = userNicknamesAndPasswords
                                                .Where(user => user.Nickname != userNicknameAndPassword.Nickname)
                                                .ToList();
                    userNicknamesAndPasswords.Add(userNicknameAndPassword);
                    fileMaster.WriteData(FilePath, userNicknamesAndPasswords);
                    Console.WriteLine("Password changed");
                }

                fileMaster.AddData(userNicknameAndPassword, FilePath);
                Console.WriteLine("Saving is successful");
            }
        }
コード例 #2
0
 private bool EnterWithSavedAccount(UserNicknameAndPassword userNicknameAndPassword)
 {
     AnswerServer();
     if (communication.data.ToString() == "Enter a nickname")
     {
         SendMessage(userNicknameAndPassword.Nickname);
         AnswerServer();
         if (communication.data.ToString() == "Enter password bigger than 7 symbols")
         {
             SendMessage(userNicknameAndPassword.Password);
             AnswerAndWriteServer();
             if (communication.data.ToString() == "You enter to messenger")
             {
                 return(true);
             }
         }
     }
     return(false);
 }