Advertisement
lucacodorean

Untitled

Mar 27th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.76 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.IO;
  11. using System.Data.OleDb;
  12. using System.Net.Mail;
  13. using System.Security.Permissions;
  14. using Microsoft.Win32;
  15. using System.Runtime.InteropServices;
  16. using System.Data.SqlClient;
  17. using MySql.Data.MySqlClient;
  18. using System.Net;
  19. using System.Drawing.Drawing2D;
  20.  
  21.  
  22. namespace Unirea
  23. {
  24.     public partial class REGISTER : Form
  25.     {
  26.  
  27.         public frmMesaj fmes;
  28.         public REGISTER()
  29.         {
  30.             InitializeComponent();
  31.         }
  32.         bool adresa = false;
  33.         public static string CreateMD5(string input)
  34.         {
  35.             using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
  36.             {
  37.                 byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
  38.                 byte[] hashBytes = md5.ComputeHash(inputBytes);
  39.  
  40.                 StringBuilder sb = new StringBuilder();
  41.                 for (int i = 0; i < hashBytes.Length; i++)
  42.                 {
  43.                     sb.Append(hashBytes[i].ToString("X2"));
  44.                 }
  45.                 return sb.ToString();
  46.             }
  47.         }
  48.  
  49.         private void button1_Click(object sender, EventArgs e)
  50.         {
  51.             bool oke = true;
  52.  
  53.  
  54.             variabila.nume = txtnume.Text;
  55.             variabila.mail = txtmail.Text;
  56.             variabila.parola = txtparola.Text;
  57.             variabila.mprofesor = txtMailProfesor.Text;
  58.            
  59.  
  60.             if (btnCP.Text == "Cont profesor")
  61.             {
  62.                 variabila.tip = "elev";
  63.             }
  64.             else
  65.             {
  66.                 variabila.tip = "profesor";
  67.             }
  68.  
  69.             string cale = Path.GetDirectoryName(Application.ExecutablePath);
  70.  
  71.             OleDbConnection con = new OleDbConnection(variabila.cale);
  72.             con.Open();
  73.  
  74.             OleDbCommand cmd = new OleDbCommand();
  75.             cmd.Connection = con;
  76.  
  77.             string qs = "select * from utilizatori where mail = @mail";
  78.  
  79.  
  80.  
  81.             OleDbCommand com = new OleDbCommand(qs, con);
  82.             com.CommandText = qs;
  83.             com.Parameters.AddWithValue("mail", txtmail.Text);
  84.             OleDbDataReader r = com.ExecuteReader();
  85.  
  86.             if (r.Read())
  87.             {
  88.  
  89.                 variabila.mesaj = "Acest mail exista deja!";
  90.                 fmes = new frmMesaj();
  91.                 fmes.Show();
  92.  
  93.                 oke = false;
  94.             }
  95.  
  96.             else
  97.             {
  98.                 if (variabila.ExistaNet == true)
  99.                 { verificaMail(); }
  100.                 else
  101.                 { adresa = true; }
  102.  
  103.                 if (adresa)
  104.                 {
  105.                     variabila.parola = CreateMD5(variabila.parola);
  106.  
  107.                     cmd.CommandText = "insert into utilizatori(nume , mail, parola, mailprofesor, nivel) values (@nume , @mail, @parola , @mailprofesor, @nivel)";
  108.                     cmd.Parameters.AddWithValue("nume", variabila.nume);
  109.                     cmd.Parameters.AddWithValue("mail", variabila.mail);
  110.                     cmd.Parameters.AddWithValue("parola", variabila.parola);
  111.                     cmd.Parameters.AddWithValue("mailProfesor", variabila.mprofesor);
  112.                     cmd.Parameters.AddWithValue("nivel", variabila.tip);
  113.  
  114.                     int cate = cmd.ExecuteNonQuery();
  115.  
  116.                     if (cate > 0 && variabila.nume != "" && variabila.parola != "" && variabila.mail != "" && oke == true && adresa == true)
  117.                     {
  118.                        
  119.  
  120.                         variabila.mesaj = "Te-ai inregistrat cu succes!";
  121.                         fmes = new frmMesaj();
  122.                         fmes.Show();
  123.  
  124.  
  125.                        
  126.                     }
  127.  
  128.                     if(variabila.ExistaNet == true)
  129.                     {
  130.                         try
  131.                         {
  132.                             string s = variabila.site + "/inserareUtilizatori.php?pass=parolaFoarteSugestivaPentruBazaDeDateid6296242_softCareEsteBazaDeDateALuiSamy&nume=" + variabila.nume + "&mail=" + variabila.mail + "&mailProfesor=" + variabila.mprofesor + "&parola=" + variabila.parola + "&nivel=" + variabila.tip;
  133.  
  134.                             StreamReader inStream;
  135.                             WebRequest webRequest;
  136.                             WebResponse webresponse;
  137.                             webRequest = WebRequest.Create(s);
  138.                             webresponse = webRequest.GetResponse();
  139.                             inStream = new StreamReader(webresponse.GetResponseStream());                                
  140.                             inStream.Close();
  141.                         }
  142.                         catch (Exception ex)
  143.                         {
  144.                            
  145.                         }
  146.                     }
  147.  
  148.                     OleDbCommand cmd2 = new OleDbCommand();
  149.                     cmd2.Connection = con;
  150.  
  151.                     string qs2 = "select * from utilizatori order by id2 desc";
  152.  
  153.  
  154.  
  155.                     OleDbCommand com2 = new OleDbCommand(qs2, con);
  156.                     com2.CommandText = qs2;
  157.                     OleDbDataReader r2 = com2.ExecuteReader();
  158.  
  159.                    
  160.  
  161.                     if (r2.Read())
  162.                     {
  163.                         aux = int.Parse(r2["id2"].ToString());
  164.                     }
  165.  
  166.                     variabila.id = (aux + 1).ToString();
  167.  
  168.                     OleDbCommand cmdUpdate = new OleDbCommand();
  169.                     cmdUpdate.Connection = con;
  170.  
  171.                     cmdUpdate.CommandText = "update utilizatori set id2 = @id2 where nume = @nume";
  172.                     cmdUpdate.Parameters.AddWithValue("id2", variabila.id);
  173.                     cmdUpdate.Parameters.AddWithValue("nume", variabila.nume);
  174.  
  175.                     cmdUpdate.ExecuteNonQuery();
  176.  
  177.                     r2.Close();
  178.                     con.Close();
  179.                     r.Close();
  180.  
  181.  
  182.                     this.Close();
  183.                 }
  184.  
  185.  
  186.  
  187.             }
  188.  
  189.         }
  190.  
  191.         int aux;
  192.         SmtpClient server;
  193.  
  194.         private void verificaMail()
  195.         {
  196.             server = new SmtpClient("smtp.gmail.com", 587);
  197.             server.Credentials = new System.Net.NetworkCredential("19182018q@gmail.com", "parolaComplicata");
  198.  
  199.             try
  200.             {
  201.                 MailMessage mail = new MailMessage();
  202.                 mail.From = new MailAddress("19182018q@gmail.com");
  203.                 mail.To.Add(txtMailProfesor.Text);
  204.                 mail.Subject = "TESTARE";
  205.                 mail.Body = "";
  206.                 server.EnableSsl = true;
  207.                 server.Send(mail);
  208.                 /*(this.MdiParent as frmMain).fmes.ShowDialog();
  209.                 (this.MdiParent as frmMain).fmes.lblMesaj.Text = "Mail timis cu succes!";*/
  210.                 adresa = true;
  211.             }
  212.             catch (Exception ex)
  213.             {
  214.                 variabila.mesaj = "Adresa de mail a profesorului nu exista!";
  215.                 fmes = new frmMesaj();
  216.                 fmes.Show();
  217.  
  218.                 /*(this.MdiParent as frmMain).fmes.ShowDialog();
  219.                 (this.MdiParent as frmMain).fmes.lblMesaj.Text = ;*/
  220.  
  221.                 adresa = false;
  222.             }
  223.  
  224.             try
  225.             {
  226.                 MailMessage mail2 = new MailMessage();
  227.                 mail2.From = new MailAddress("19182018q@gmail.com");
  228.                 mail2.To.Add(txtmail.Text);
  229.                 mail2.Subject = "TESTARE";
  230.                 mail2.Body = "";
  231.                 server.EnableSsl = true;
  232.                 server.Send(mail2);
  233.                 /*(this.MdiParent as frmMain).fmes.ShowDialog();
  234.                 (this.MdiParent as frmMain).fmes.lblMesaj.Text = "Mail timis cu succes!";*/
  235.                 adresa = true;
  236.             }
  237.             catch (Exception ex2)
  238.             {
  239.                 variabila.mesaj = "Adresa ta de mail nu exista!";
  240.                fmes = new frmMesaj();
  241.                 fmes.Show();
  242.                 //(this.MdiParent as frmMain).fmes.MdiParent = this;
  243.  
  244.                 adresa = false;
  245.             }
  246.         }
  247.  
  248.         private void label5_Click(object sender, EventArgs e)
  249.         {
  250.             this.Close();
  251.         }
  252.  
  253.         private void REGISTER_FormClosed(object sender, FormClosedEventArgs e)
  254.         {
  255.             if (variabila.nume != "")
  256.             {
  257.                 variabila.fst.Controls["lblNume"].Text = variabila.nume + "!";
  258.                 variabila.fst.Controls["lblNume"].Visible = true;
  259.                 variabila.fst.Controls["lblBAV"].Visible = true;
  260.             }
  261.  
  262.             variabila.arataFrmMain = true;
  263.         }
  264.  
  265.         void bordura()
  266.         {
  267.             int grosime = 20;
  268.             pbSt.Size = pbDr.Size = new Size(grosime, this.Height);
  269.             pbSus.Size = pbJos.Size = new Size(this.Width, grosime);
  270.             pbSus.Location = new Point(0, 0);
  271.             pbJos.Location = new Point(0, this.Height - grosime);
  272.             pbSt.Location = new Point(0, 0);
  273.             pbDr.Location = new Point(this.Width - grosime, 0);
  274.             pbClose.Location = new Point(this.Width - 25 - pbClose.Width, 25);
  275.         }
  276.         Point lastPoint;
  277.         private void bibliografie_MouseMove(object sender, MouseEventArgs e)
  278.         {
  279.             if (e.Button == MouseButtons.Left)
  280.             {
  281.                 this.Left += e.X - lastPoint.X;
  282.                 this.Top += e.Y - lastPoint.Y;
  283.             }
  284.         }
  285.  
  286.  
  287.  
  288.         private void bibliografie_MouseDown(object sender, MouseEventArgs e)
  289.         {
  290.             lastPoint = new Point(e.X, e.Y);
  291.         }
  292.         private void REGISTER_Load(object sender, EventArgs e)
  293.         {
  294.             bordura();
  295.         }
  296.  
  297.         private void pbClose_Click(object sender, EventArgs e)
  298.         {
  299.             this.Close();
  300.         }
  301.  
  302.         private void btnShowPass_Click(object sender, EventArgs e)
  303.         {
  304.             if (btnShowPass.Text == "Arata parola")
  305.             {
  306.                 txtparola.PasswordChar = '\0';
  307.                 btnShowPass.Text = "Ascunde parola";
  308.             }
  309.             else
  310.             {
  311.                 txtparola.PasswordChar = '•';
  312.                 btnShowPass.Text = "Arata parola";
  313.             }
  314.         }
  315.  
  316.         private void btnCP_Click(object sender, EventArgs e)
  317.         {
  318.             if(btnCP.Text == "Cont profesor")
  319.             {
  320.                 btnCP.Text = "Cont elev";
  321.                 lblMP.Visible = txtMailProfesor.Visible = false;
  322.             }
  323.             else
  324.             {
  325.                 btnCP.Text = "Cont profesor";
  326.                 lblMP.Visible = txtMailProfesor.Visible = true;
  327.             }
  328.         }
  329.     }
  330. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement