Exemplo n.º 1
0
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            string emailOrMobile = txtLoginMobile.Text;
            string password      = txtLoginPassword.Text;

            if (!(forEmail.Match(emailOrMobile).Success || forPhone.Match(emailOrMobile).Success))
            {
                MessageBox.Show("Invalid Username Or Password.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                connection = new OleDbConnection(connectionString);
                string query = "SELECT * FROM UserData WHERE MOBILE = '" + emailOrMobile + "';";
                connection.Open();
                command = new OleDbCommand(query, connection);
                OleDbDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    reader.Read();
                    string firstName     = reader[1].ToString();
                    string surName       = reader[2].ToString();
                    string mobileOrEmail = reader[3].ToString();
                    byte[] key           = GenerateKey(firstName, surName, mobileOrEmail);
                    string dbPassword    = blockCipher.Decrypt(reader[4].ToString(), key);
                    if (password == dbPassword)
                    {
                        MessageBox.Show("Login Successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Invalid Password.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Invalid Username.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                connection.Close();
                command.Dispose();
            }
        }
Exemplo n.º 2
0
        public static void Listener()
        {
            while (IsOpen)
            {
                var endPoint = new IPEndPoint(IPAddress.Any, 0);
                while (Sock.Available > 0)
                {
                    var data = Sock.Receive(ref endPoint);
                    LastMessageIn = DateTime.UtcNow;

                    bool readRaw = Encryptor == null ||
                                   data.Take(Packet.MagicNumber.Length).SequenceEqual(Packet.MagicNumber);

                    Packet packet =
                        readRaw ? Packet.FromBytes(data)
                                : Packet.FromBytes(Encryptor.Decrypt(data));

                    switch ((kIntraMasterId)packet.Id)
                    {
                    case kIntraMasterId.KeyExchange:
                        var responsePacket = Key.ParseRequestPacket(packet);
                        Encryptor = new BlockCipher(Key.PrivateKey);
                        if (responsePacket != null)
                        {
                            Send(responsePacket);
                        }
                        else
                        {
                            LastMessageIn = new DateTime(0);
                        }
                        break;

                    case kIntraMasterId.PositiveAck:
                        Console.WriteLine($"Packet type {packet[0].Raw[0]} accepted by master");
                        break;

                    case kIntraMasterId.NegativeAck:
                        Console.WriteLine($"Packet type {packet[0].Raw[0]} declined by master for reason {packet[1].Str}");
                        break;

                    case kIntraMasterId.EncryptionError:
                        Key           = new Key();
                        Encryptor     = null;
                        LastMessageIn = new DateTime(0);
                        break;
                    }
                }

                if (Encryptor != null)
                {
                    if (DeltaLastOut.TotalSeconds > 2)
                    {
                        SendEncrypted(ServerContext.StatusUpdatePacket);
                    }
                }
                else
                if (DeltaLastOut.TotalSeconds > 10)
                {
                    Send(new Packet(kIntraSlaveId.InitiationAttempt, Configuration.General["Master Secret"].Str));
                }

                Thread.Sleep(1);
            }
        }