Пример #1
0
        private static bool CheckRegistrationData(string text, Socket currentSocket) //Check for registration accessibility.
        {
            string[] arr      = text.Split('_');
            string   login    = Encryptor.EncryptString(arr[1]);
            string   password = Encryptor.EncryptString(arr[2]);
            string   email    = Encryptor.EncryptString(arr[3]);
            string   phone    = Encryptor.EncryptString(arr[4]);
            string   uniqid   = arr[5];

            if (File.Exists(@"ClientsData\" + uniqid + ".ld"))
            {
                string[] pth   = Directory.GetFiles(clientsDirectoryPath);
                int      count = 0;
                foreach (var currentPath in pth)
                {
                    count++;
                    if (File.ReadAllText(currentPath).Contains(login))
                    {
                        SendSocketData("err_lgn", currentSocket);
                        Log("Failed to register new user!", false, LogStates.Program, Flag_LogMessageDate);
                        return(false);
                    }
                    else if (File.ReadAllText(currentPath).Contains(email))
                    {
                        SendSocketData("err_eml", currentSocket);
                        Log("Failed to register new user!", false, LogStates.Program, Flag_LogMessageDate);
                        return(false);
                    }
                    else if (File.ReadAllText(currentPath).Contains(phone))
                    {
                        SendSocketData("err_phn", currentSocket);
                        Log("Failed to register new user!", false, LogStates.Program, Flag_LogMessageDate);
                        return(false);
                    }
                }
                File.Create(@"ClientsData\" + uniqid + "_" + count.ToString() + ".ld").Close();
                Log("New file created: " + uniqid + "_" + count.ToString() + ".ld", false, LogStates.Program, Flag_LogMessageDate);
                File.AppendAllText(@"ClientsData\" + uniqid + "_" + count.ToString() + ".ld", BuildRegistrationStringDecrypted(login, password, email, phone));
                Log("Appended text to file " + uniqid + "_" + count.ToString() + ".ld" + ": " + BuildRegistrationStringDecrypted(login, password, email, phone), false, LogStates.Program, Flag_LogMessageDate);
                byte[] data_2 = Encoding.Unicode.GetBytes(Encryptor.EncryptString("acc"));
                currentSocket.Send(data_2);
                return(true);
            }
            else
            {
                string[] pth = Directory.GetFiles(clientsDirectoryPath);
                foreach (var currentPath in pth)
                {
                    if (File.ReadAllText(currentPath).Contains(login))
                    {
                        SendSocketData("err_lgn", currentSocket);
                        Log("Failed to register new user!", false, LogStates.Program, Flag_LogMessageDate);
                        return(false);
                    }
                    else if (File.ReadAllText(currentPath).Contains(email))
                    {
                        SendSocketData("err_eml", currentSocket);
                        Log("Failed to register new user!", false, LogStates.Program, Flag_LogMessageDate);
                        return(false);
                    }
                    else if (File.ReadAllText(currentPath).Contains(phone))
                    {
                        SendSocketData("err_phn", currentSocket);
                        Log("Failed to register new user!", false, LogStates.Program, Flag_LogMessageDate);
                        return(false);
                    }
                }
                File.Create(@"ClientsData\" + uniqid + ".ld").Close();
                Log("New file created: " + uniqid + ".ld", false, LogStates.Program, Flag_LogMessageDate);
                File.AppendAllText(@"ClientsData\" + uniqid + ".ld", BuildRegistrationStringDecrypted(login, password, email, phone));
                Log("Appended text to file " + uniqid + ".ld" + ": " + BuildRegistrationStringDecrypted(login, password, email, phone), false, LogStates.Program, Flag_LogMessageDate);
                byte[] data_2 = Encoding.Unicode.GetBytes(Encryptor.EncryptString("acc"));
                currentSocket.Send(data_2);
                return(true);
            }
        }
Пример #2
0
 private static void SendSocketData(string data_txt, Socket currentSocket) //Send data to client.
 {
     byte[] data = Encoding.Unicode.GetBytes(Encryptor.EncryptString(data_txt));
     currentSocket.Send(data);
 }