Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- using System.Data.OleDb;
- using System.Net.Mail;
- using System.Security.Permissions;
- using Microsoft.Win32;
- using System.Runtime.InteropServices;
- using System.Data.SqlClient;
- using MySql.Data.MySqlClient;
- using System.Net;
- using System.Drawing.Drawing2D;
- namespace Unirea
- {
- public partial class REGISTER : Form
- {
- public frmMesaj fmes;
- public REGISTER()
- {
- InitializeComponent();
- }
- bool adresa = false;
- public static string CreateMD5(string input)
- {
- using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
- {
- byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
- byte[] hashBytes = md5.ComputeHash(inputBytes);
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < hashBytes.Length; i++)
- {
- sb.Append(hashBytes[i].ToString("X2"));
- }
- return sb.ToString();
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- bool oke = true;
- variabila.nume = txtnume.Text;
- variabila.mail = txtmail.Text;
- variabila.parola = txtparola.Text;
- variabila.mprofesor = txtMailProfesor.Text;
- if (btnCP.Text == "Cont profesor")
- {
- variabila.tip = "elev";
- }
- else
- {
- variabila.tip = "profesor";
- }
- string cale = Path.GetDirectoryName(Application.ExecutablePath);
- OleDbConnection con = new OleDbConnection(variabila.cale);
- con.Open();
- OleDbCommand cmd = new OleDbCommand();
- cmd.Connection = con;
- string qs = "select * from utilizatori where mail = @mail";
- OleDbCommand com = new OleDbCommand(qs, con);
- com.CommandText = qs;
- com.Parameters.AddWithValue("mail", txtmail.Text);
- OleDbDataReader r = com.ExecuteReader();
- if (r.Read())
- {
- variabila.mesaj = "Acest mail exista deja!";
- fmes = new frmMesaj();
- fmes.Show();
- oke = false;
- }
- else
- {
- if (variabila.ExistaNet == true)
- { verificaMail(); }
- else
- { adresa = true; }
- if (adresa)
- {
- variabila.parola = CreateMD5(variabila.parola);
- cmd.CommandText = "insert into utilizatori(nume , mail, parola, mailprofesor, nivel) values (@nume , @mail, @parola , @mailprofesor, @nivel)";
- cmd.Parameters.AddWithValue("nume", variabila.nume);
- cmd.Parameters.AddWithValue("mail", variabila.mail);
- cmd.Parameters.AddWithValue("parola", variabila.parola);
- cmd.Parameters.AddWithValue("mailProfesor", variabila.mprofesor);
- cmd.Parameters.AddWithValue("nivel", variabila.tip);
- int cate = cmd.ExecuteNonQuery();
- if (cate > 0 && variabila.nume != "" && variabila.parola != "" && variabila.mail != "" && oke == true && adresa == true)
- {
- variabila.mesaj = "Te-ai inregistrat cu succes!";
- fmes = new frmMesaj();
- fmes.Show();
- }
- if(variabila.ExistaNet == true)
- {
- try
- {
- string s = variabila.site + "/inserareUtilizatori.php?pass=parolaFoarteSugestivaPentruBazaDeDateid6296242_softCareEsteBazaDeDateALuiSamy&nume=" + variabila.nume + "&mail=" + variabila.mail + "&mailProfesor=" + variabila.mprofesor + "&parola=" + variabila.parola + "&nivel=" + variabila.tip;
- StreamReader inStream;
- WebRequest webRequest;
- WebResponse webresponse;
- webRequest = WebRequest.Create(s);
- webresponse = webRequest.GetResponse();
- inStream = new StreamReader(webresponse.GetResponseStream());
- inStream.Close();
- }
- catch (Exception ex)
- {
- }
- }
- OleDbCommand cmd2 = new OleDbCommand();
- cmd2.Connection = con;
- string qs2 = "select * from utilizatori order by id2 desc";
- OleDbCommand com2 = new OleDbCommand(qs2, con);
- com2.CommandText = qs2;
- OleDbDataReader r2 = com2.ExecuteReader();
- if (r2.Read())
- {
- aux = int.Parse(r2["id2"].ToString());
- }
- variabila.id = (aux + 1).ToString();
- OleDbCommand cmdUpdate = new OleDbCommand();
- cmdUpdate.Connection = con;
- cmdUpdate.CommandText = "update utilizatori set id2 = @id2 where nume = @nume";
- cmdUpdate.Parameters.AddWithValue("id2", variabila.id);
- cmdUpdate.Parameters.AddWithValue("nume", variabila.nume);
- cmdUpdate.ExecuteNonQuery();
- r2.Close();
- con.Close();
- r.Close();
- this.Close();
- }
- }
- }
- int aux;
- SmtpClient server;
- private void verificaMail()
- {
- server = new SmtpClient("smtp.gmail.com", 587);
- server.Credentials = new System.Net.NetworkCredential("19182018q@gmail.com", "parolaComplicata");
- try
- {
- MailMessage mail = new MailMessage();
- mail.From = new MailAddress("19182018q@gmail.com");
- mail.To.Add(txtMailProfesor.Text);
- mail.Subject = "TESTARE";
- mail.Body = "";
- server.EnableSsl = true;
- server.Send(mail);
- /*(this.MdiParent as frmMain).fmes.ShowDialog();
- (this.MdiParent as frmMain).fmes.lblMesaj.Text = "Mail timis cu succes!";*/
- adresa = true;
- }
- catch (Exception ex)
- {
- variabila.mesaj = "Adresa de mail a profesorului nu exista!";
- fmes = new frmMesaj();
- fmes.Show();
- /*(this.MdiParent as frmMain).fmes.ShowDialog();
- (this.MdiParent as frmMain).fmes.lblMesaj.Text = ;*/
- adresa = false;
- }
- try
- {
- MailMessage mail2 = new MailMessage();
- mail2.From = new MailAddress("19182018q@gmail.com");
- mail2.To.Add(txtmail.Text);
- mail2.Subject = "TESTARE";
- mail2.Body = "";
- server.EnableSsl = true;
- server.Send(mail2);
- /*(this.MdiParent as frmMain).fmes.ShowDialog();
- (this.MdiParent as frmMain).fmes.lblMesaj.Text = "Mail timis cu succes!";*/
- adresa = true;
- }
- catch (Exception ex2)
- {
- variabila.mesaj = "Adresa ta de mail nu exista!";
- fmes = new frmMesaj();
- fmes.Show();
- //(this.MdiParent as frmMain).fmes.MdiParent = this;
- adresa = false;
- }
- }
- private void label5_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void REGISTER_FormClosed(object sender, FormClosedEventArgs e)
- {
- if (variabila.nume != "")
- {
- variabila.fst.Controls["lblNume"].Text = variabila.nume + "!";
- variabila.fst.Controls["lblNume"].Visible = true;
- variabila.fst.Controls["lblBAV"].Visible = true;
- }
- variabila.arataFrmMain = true;
- }
- void bordura()
- {
- int grosime = 20;
- pbSt.Size = pbDr.Size = new Size(grosime, this.Height);
- pbSus.Size = pbJos.Size = new Size(this.Width, grosime);
- pbSus.Location = new Point(0, 0);
- pbJos.Location = new Point(0, this.Height - grosime);
- pbSt.Location = new Point(0, 0);
- pbDr.Location = new Point(this.Width - grosime, 0);
- pbClose.Location = new Point(this.Width - 25 - pbClose.Width, 25);
- }
- Point lastPoint;
- private void bibliografie_MouseMove(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- this.Left += e.X - lastPoint.X;
- this.Top += e.Y - lastPoint.Y;
- }
- }
- private void bibliografie_MouseDown(object sender, MouseEventArgs e)
- {
- lastPoint = new Point(e.X, e.Y);
- }
- private void REGISTER_Load(object sender, EventArgs e)
- {
- bordura();
- }
- private void pbClose_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void btnShowPass_Click(object sender, EventArgs e)
- {
- if (btnShowPass.Text == "Arata parola")
- {
- txtparola.PasswordChar = '\0';
- btnShowPass.Text = "Ascunde parola";
- }
- else
- {
- txtparola.PasswordChar = '•';
- btnShowPass.Text = "Arata parola";
- }
- }
- private void btnCP_Click(object sender, EventArgs e)
- {
- if(btnCP.Text == "Cont profesor")
- {
- btnCP.Text = "Cont elev";
- lblMP.Visible = txtMailProfesor.Visible = false;
- }
- else
- {
- btnCP.Text = "Cont profesor";
- lblMP.Visible = txtMailProfesor.Visible = true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement