Advertisement
Guest User

Login

a guest
Jan 19th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Xml.Serialization;
  11. using System.IO;
  12. using System.Net;
  13.  
  14.  
  15. namespace APID_TOOL_Manager
  16. {
  17. public partial class Login : Form
  18. {
  19. public Login()
  20. {
  21. InitializeComponent();
  22. var app_dir = Path.GetDirectoryName(Application.ExecutablePath);
  23. Gecko.Xpcom.Initialize(Path.Combine(app_dir, "xulrunner"));
  24. }
  25.  
  26. private void Login_Load(object sender, EventArgs e)
  27. {
  28.  
  29. }
  30.  
  31. private void btnLogin_Click(object sender, EventArgs e)
  32. {
  33. SubmitData();
  34. }
  35.  
  36. public virtual CookieContainer CookieContainer { get; set; }
  37.  
  38. public void SubmitData()
  39. {
  40. try
  41. {
  42.  
  43. string apiUser = "phpcode";
  44. string apiPass = "29012901";
  45.  
  46.  
  47. ASCIIEncoding encoding = new ASCIIEncoding();
  48.  
  49. string postData = "user=" + apiUser + "&pass=" + apiPass;
  50. byte[] data = encoding.GetBytes(postData);
  51.  
  52. WebRequest webRequest = WebRequest.Create("http://newapidtool.riek-media.com/index.php");
  53.  
  54. HttpWebRequest request = (HttpWebRequest)webRequest;
  55.  
  56. CookieContainer cookieContainer = new CookieContainer();
  57. request.CookieContainer = cookieContainer;
  58.  
  59. request.Method = "POST";
  60. request.ContentType = "application/x-www-form-urlencoded";
  61. request.ContentLength = data.Length;
  62.  
  63. Stream stream = request.GetRequestStream();
  64. stream.Write(data, 0, data.Length);
  65. stream.Close();
  66.  
  67. WebResponse response = request.GetResponse();
  68. stream = response.GetResponseStream();
  69.  
  70. StreamReader sr = new StreamReader(stream);
  71.  
  72. if (sr.ReadToEnd() == "true")
  73. {
  74.  
  75. Dashboard dashboard = new Dashboard();
  76. // Wir weisen unserer Form2 die Variable zu
  77. dashboard.apiUser = apiUser;
  78. dashboard.apiPass = apiPass;
  79.  
  80. dashboard.Show();
  81. Hide();
  82. }
  83. else
  84. {
  85. MessageBox.Show("Deine Logindaten waren fehlerhaft. Sollte der Fehler weiterhin auftreten, setze dich mit der IT-Apteilung in Verbindung.",
  86. "Login Error!",
  87. MessageBoxButtons.OK,
  88. MessageBoxIcon.Warning // for Warning
  89. //MessageBoxIcon.Error // for Error
  90. //MessageBoxIcon.Information // for Information
  91. //MessageBoxIcon.Question // for Question
  92. );
  93.  
  94.  
  95. }
  96.  
  97. sr.Close();
  98. stream.Close();
  99. }
  100.  
  101. catch (Exception ex)
  102. {
  103. MessageBox.Show("Error : " + ex.Message);
  104. }
  105.  
  106.  
  107. }
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement