Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Threading;
- using System.Net;
- using System.Net.Sockets;
- using System.IO;
- namespace Cpanel_Server
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- Thread tStartListen = new Thread(new ThreadStart(Listen));
- tStartListen.IsBackground = true;
- tStartListen.Start();
- }
- Socket client;
- private void Listen()
- {
- Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- listener.Bind(new IPEndPoint(IPAddress.Any, 4444));
- listener.Listen(100);
- while(true)
- {
- client = listener.Accept();
- Thread tStartInteract = new Thread(new ThreadStart(Interact));
- tStartInteract.Start();
- }
- }
- private void Interact()
- {
- UserControl control = new UserControl();
- Socket newClient = client;
- NetworkStream stream = new NetworkStream(newClient);
- byte[] buffer = new byte[newClient.SendBufferSize];
- int bytesRead = newClient.Receive(buffer);
- byte[] formatted = new byte[bytesRead];
- for (int i = 0; i < bytesRead; i++)
- {
- formatted[i] = buffer[i];
- }
- string rawText = Encoding.ASCII.GetString(formatted);
- string userName = rawText.Substring(0, rawText.IndexOf("-//SPLIT\\-"));
- string password = rawText.Substring(rawText.IndexOf("-//SPLIT\\-"));
- control.userName = userName;
- if (control.ReadUser())
- {
- if (password == control.password)
- {
- string loginResult = "Login Successful!";
- if (stream.CanWrite)
- {
- stream.Write(Encoding.ASCII.GetBytes(loginResult), 0, loginResult.Length);
- stream.Flush();
- }
- }
- else
- {
- string loginResult = "Wrong Password!";
- if (stream.CanWrite)
- {
- stream.Write(Encoding.ASCII.GetBytes(loginResult), 0, loginResult.Length);
- stream.Flush();
- }
- }
- }
- else
- {
- string loginResult = "Wrong Username!";
- if (stream.CanWrite)
- {
- stream.Write(Encoding.ASCII.GetBytes(loginResult), 0, loginResult.Length);
- stream.Flush();
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment