Advertisement
-Annie-

SendEmail

Feb 2nd, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.26 KB | None | 0 0
  1. namespace SendEmail
  2. {
  3.     using System;
  4.     using System.IO;
  5.  
  6.     public static class Program
  7.     {
  8.         public static void Main()
  9.         {
  10.             string neededUser = "suAdmin";
  11.             string neededPasswor = "aDmInPw17";
  12.  
  13.             Console.WriteLine("Content-Type: text/html\r\n");
  14.             string request = Environment.GetEnvironmentVariable("REQUEST_METHOD").ToLower();
  15.  
  16.             Console.WriteLine("<!DOCTYPE html>\r\n<html>\r\n<head>\r\n\t<title>Document</title>\r\n</head>\r\n<body>");
  17.  
  18.             if (request == "get")
  19.             {
  20.                 PrintGetForm();
  21.             }
  22.  
  23.             else if (request == "post")
  24.             {
  25.                 string[] postData = Console.ReadLine().Split('&');
  26.                 string givenUsername = postData[0].Split('=')[1];
  27.                 string givenPassword = postData[1].Split('=')[1];
  28.  
  29.                 if (givenUsername == neededUser & givenPassword == neededPasswor)
  30.                 {
  31.                     PrintPostForm();
  32.                 }
  33.                 else
  34.                 {
  35.                     PrintGetForm();
  36.                     Console.WriteLine("<p style=\"color: red;\">Invalid username or pass!</p>");
  37.                 }
  38.             }
  39.  
  40.             Console.WriteLine("</body>\r\n</html>");
  41.         }
  42.  
  43.         static void PrintGetForm()
  44.         {
  45.             Console.WriteLine("<h2>Login: </h2>\r\n\t<form action=\"SendEmail.exe\" method=\"POST\">\r\n\t\t<label for=\"username\">Username: </label>\r\n\t\t<input type=\"text\" name=\"username\" id=\"username\">\r\n\t\t<label for=\"password\">Password: </label>\r\n\t\t<input type=\"password\" name=\"password\">\r\n\t\t<input type=\"submit\" name=\"submit\" value=\"Login\">\r\n\t</form>");
  46.         }
  47.  
  48.         static void PrintPostForm()
  49.         {
  50.             Console.WriteLine("<h2>Hello suAdmin</h2>\r\n\t<form action=\"\" method=\"POST\">\r\n\t\t<label for=\"to\">To: </label>\r\n\t\t<input type=\"text\" name=\"to\" id=\"to\">\r\n\t\t<label for=\"subject\">Subject: </label>\r\n\t\t<input type=\"text\" name=\"subject\" id=\"subject\">\r\n\t\t<label for=\"message\">Message: </label>\r\n\t\t<textarea id=\"message\"></textarea>\r\n\t\t<input type=\"submit\" name=\"send\" value=\"Send\">\r\n\t</form>");
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement