Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data;
- using System.Data.SqlClient;
- using System.Net;
- using System.Net.Mail;
- using System.Net.Sockets;
- using System.Text;
- using static System.Console;
- namespace UnlimitedUSBLoginServer
- {
- class Program
- {
- static void Main(string[] args)
- {
- int port = 7867;
- TcpListener listener = new TcpListener(IPAddress.Any, port);
- WriteLine("Programma in ascolto sulla porta {0}/TCP", port);
- listener.Start();
- while (true)
- {
- string Messaggio = "", Username = "", Password = "";
- Socket client = listener.AcceptSocket();
- WriteLine("Connessione accettata ({0}).", client.RemoteEndPoint);
- byte[] data = new byte[100];
- int size = client.Receive(data);
- for (int i = 0; i < size; i++)
- Messaggio += Convert.ToChar(data[i]);
- Username = Messaggio.Split('|')[0];
- Password = Messaggio.Split('|')[1];
- client.Send(Encoding.Unicode.GetBytes(SQL(Username, Password)));
- client.Close();
- WriteLine("Dati inviati\n");
- }
- }
- static string SQL(string Username, string Password)
- {
- string Cartella = "", PasswordQUERY = "", IndirizzoMail = "";
- int Tentativi = 1;
- using (var connection = new SqlConnection("Server=tcp:usbcloud.database.windows.net,1433;Initial Catalog=USBCLOUDDB;Persist Security Info=False;User ID=USBCLOUD;Password=@Nannuzzicrew;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"))
- {
- connection.Open();
- using (var command = new SqlCommand())
- {
- command.Connection = connection;
- command.CommandType = CommandType.Text;
- command.CommandText = "SELECT Cartella,Tentativi,Password,E-MAIL FROM [dbo].[Database] WHERE Username = '" + Username + "'";
- SqlDataReader reader = command.ExecuteReader();
- while (reader.Read())
- {
- Cartella = reader.GetString(0).Replace(" ", String.Empty);
- Tentativi = reader.GetInt32(1);
- PasswordQUERY = reader.GetString(2).Replace(" ", String.Empty);
- IndirizzoMail = reader.GetString(3).Replace(" ", String.Empty);
- }
- reader.Close();
- if (Password == PasswordQUERY && Tentativi < 5)
- {
- return Cartella;
- }
- else if (Password == PasswordQUERY && Tentativi >= 5)
- {
- return "1";
- }
- else
- {
- if (Tentativi == 5)
- MAIL(IndirizzoMail);
- command.CommandText = " UPDATE [dbo].[Database] SET Tentativi =" + (Tentativi + 1) + "WHERE Username = '" + Username + "'";
- command.ExecuteReader();
- return "0";
- }
- }
- }
- }
- static void MAIL(string IndirizzoMail)
- {
- MailMessage mail = new MailMessage();
- SmtpClient SmtpServer = new SmtpClient("smtp.rago.ovh");
- mail.From = new MailAddress("security@rago.ovh");
- mail.To.Add(IndirizzoMail);
- mail.Subject = "Account is blocked";
- mail.Body = "Your account .....";
- SmtpServer.Port = 25;
- SmtpServer.Credentials = new NetworkCredential("security", "@Nannuzzicrew");
- SmtpServer.EnableSsl = true;
- SmtpServer.Send(mail);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement