Advertisement
Guest User

Untitled

a guest
Mar 4th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using System.Net;
  5. using System.Net.Mail;
  6. using System.Net.Sockets;
  7. using System.Text;
  8. using static System.Console;
  9.  
  10. namespace UnlimitedUSBLoginServer
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. int port = 7867;
  17. TcpListener listener = new TcpListener(IPAddress.Any, port);
  18. WriteLine("Programma in ascolto sulla porta {0}/TCP", port);
  19. listener.Start();
  20. while (true)
  21. {
  22. string Messaggio = "", Username = "", Password = "";
  23. Socket client = listener.AcceptSocket();
  24. WriteLine("Connessione accettata ({0}).", client.RemoteEndPoint);
  25. byte[] data = new byte[100];
  26. int size = client.Receive(data);
  27. for (int i = 0; i < size; i++)
  28. Messaggio += Convert.ToChar(data[i]);
  29. Username = Messaggio.Split('|')[0];
  30. Password = Messaggio.Split('|')[1];
  31. client.Send(Encoding.Unicode.GetBytes(SQL(Username, Password)));
  32. client.Close();
  33. WriteLine("Dati inviati\n");
  34. }
  35. }
  36.  
  37. static string SQL(string Username, string Password)
  38. {
  39. string Cartella = "", PasswordQUERY = "", IndirizzoMail = "";
  40. int Tentativi = 1;
  41. 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;"))
  42. {
  43. connection.Open();
  44. using (var command = new SqlCommand())
  45. {
  46. command.Connection = connection;
  47. command.CommandType = CommandType.Text;
  48. command.CommandText = "SELECT Cartella,Tentativi,Password,E-MAIL FROM [dbo].[Database] WHERE Username = '" + Username + "'";
  49. SqlDataReader reader = command.ExecuteReader();
  50. while (reader.Read())
  51. {
  52. Cartella = reader.GetString(0).Replace(" ", String.Empty);
  53. Tentativi = reader.GetInt32(1);
  54. PasswordQUERY = reader.GetString(2).Replace(" ", String.Empty);
  55. IndirizzoMail = reader.GetString(3).Replace(" ", String.Empty);
  56. }
  57. reader.Close();
  58. if (Password == PasswordQUERY && Tentativi < 5)
  59. {
  60. return Cartella;
  61. }
  62. else if (Password == PasswordQUERY && Tentativi >= 5)
  63. {
  64. return "1";
  65. }
  66. else
  67. {
  68. if (Tentativi == 5)
  69. MAIL(IndirizzoMail);
  70. command.CommandText = " UPDATE [dbo].[Database] SET Tentativi =" + (Tentativi + 1) + "WHERE Username = '" + Username + "'";
  71. command.ExecuteReader();
  72. return "0";
  73. }
  74. }
  75. }
  76. }
  77. static void MAIL(string IndirizzoMail)
  78. {
  79. MailMessage mail = new MailMessage();
  80. SmtpClient SmtpServer = new SmtpClient("smtp.rago.ovh");
  81. mail.From = new MailAddress("security@rago.ovh");
  82. mail.To.Add(IndirizzoMail);
  83. mail.Subject = "Account is blocked";
  84. mail.Body = "Your account .....";
  85. SmtpServer.Port = 25;
  86. SmtpServer.Credentials = new NetworkCredential("security", "@Nannuzzicrew");
  87. SmtpServer.EnableSsl = true;
  88. SmtpServer.Send(mail);
  89. }
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement