public bool CheckLogin(byte[] data, int id)
 {
     byte[] Login = new byte[Const.LOGIN_SIZE];
     for (int i = 0; i < Const.LOGIN_SIZE; i++)
     {
         Login[i] = data[i];
     }
     if (FileWork.CheckLoginExistence(Encoding.Unicode.GetString(Login)))
     {
         ClientsList[id - 1].isValidLogin = true;
         ClientsList[id - 1].Login        = Login;
         ClientsList[id - 1].Password     = FileWork.GetClientPassword(Encoding.Unicode.GetString(Login));
         return(true);
     }
     return(false);
 }
        public bool SetLogin(byte[] data, int id)
        {
            byte[] oldLogin   = this.ClientsList[id - 1].Login;
            byte[] DecodeData = this.ClientsList[id - 1].Cipher.decode(data);
            if (DecodeData[Const.CONTROL_NUMBER_POSITION] != Const.CONTROL_NUMBER)
            {
                this.ServerMessage("подпись невалидна", id);
                return(false);
            }
            byte[] newLogin = getData(DecodeData);

            if (this.ClientsList[id - 1].isAuthorised)
            {
                if (this.isUniqLogin(newLogin))
                {
                    this.ClientsList[id - 1].Login = newLogin;
                    this.ServerMessage("логин изменен", id);
                    BroadcastAboutNewUser(this.ClientsList[id - 1].Id, this.ClientsList[id - 1].Login,
                                          this.ClientsList[id - 1].Cipher.publicKey);
                    MessageAboutUsers(id);
                    byte[] Password = FileWork.GetClientPassword(Encoding.Unicode.GetString(oldLogin));
                    FileWork.Deletefile(Encoding.Unicode.GetString(oldLogin));
                    if (!FileWork.SaveClientInfo(Encoding.Unicode.GetString(newLogin), Password))
                    {
                        this.ServerMessage("не удалось вас зарегистрировать", id);
                        return(false);
                    }
                }
            }
            else
            {
                if (!this.isUniqLogin(newLogin))
                {
                    this.ClientsList[id - 1].Login = newLogin;
                    this.ServerMessage("логин принят", id);

                    this.ClientsList[id - 1].Password = FileWork.GetClientPassword(Encoding.Unicode.GetString(newLogin));
                    BroadcastAboutNewUser(this.ClientsList[id - 1].Id, this.ClientsList[id - 1].Login,
                                          this.ClientsList[id - 1].Cipher.publicKey);
                    MessageAboutUsers(id);
                    ///////// чтение пароля из файла
                }
                else
                {
                    this.ClientsList[id - 1].Login    = newLogin;
                    this.ClientsList[id - 1].Password = new byte[Const.PASSWORD_SIZE];
                    if (!FileWork.SaveClientInfo(Encoding.Unicode.GetString(newLogin), this.ClientsList[id - 1].Password))
                    {
                        this.ServerMessage("не удалось вас зарегистрировать", id);
                        return(false);
                    }
                    /// запись логина пароля в файл
                    this.ClientsList[id - 1].isAuthorised = true;
                    this.ClientsList[id - 1].isValidLogin = true;
                    this.ServerMessage("вы зарегистрированы: ", id);
                    BroadcastAboutNewUser(this.ClientsList[id - 1].Id, this.ClientsList[id - 1].Login,
                                          this.ClientsList[id - 1].Cipher.publicKey);
                    MessageAboutUsers(id);
                }
            }
            return(false);
        }