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.Security.Cryptography; using DatenDB; using System.Threading; namespace Deckungsbeitrag { public partial class FormLogin : Form { public Thread t; public FormLogin() { InitializeComponent(); this.groupBox1.Height = 110; this.labelPwdWh.Visible = false; this.textBoxPwdWh.Visible = false; this.buttonRegistrieren.Visible = false; } private void buttonAnmelden_Click(object sender, EventArgs e) { try { //t = new Thread(new ThreadStart(Splash)); //t.Start(); MD5 md5 = MD5.Create(); byte[] md5hash = md5.ComputeHash(Encoding.UTF8.GetBytes(this.textBoxPasswort.Text)); string pwdHash = string.Empty; foreach (byte b in md5hash) pwdHash += b.ToString("x2"); this.Person = Benutzer.Get(this.textBoxBenutzer.Text, pwdHash); this.Person.Save(); //t.Abort(); this.DialogResult = DialogResult.OK; this.Close(); } catch (LoginException lex) { //t.Abort(); switch (lex.ErrorCode) { case -1: MessageBox.Show(lex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.buttonRegistrieren.Visible = false; break; case -2: MessageBox.Show(lex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.buttonRegistrieren.Visible = false; break; case -3: MessageBox.Show(lex.Message, "Registrieren", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.buttonRegistrieren.Visible = true; this.buttonAnmelden.Enabled = false; this.groupBox1.Height = this.groupBox1.Height + 35; this.labelPwdWh.Visible = true; this.textBoxPwdWh.Visible = true; break; case -4: MessageBox.Show(lex.Message, "Server Fehler", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); break; default: break; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } private void Splash() { //Open a splash screen form FormLaden frm = new FormLaden(); Application.Run(frm); } private void buttonAbbrechen_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } public Benutzer Person { get; set; } private void buttonRegistrieren_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(this.textBoxBenutzer.Text) && !String.IsNullOrEmpty(this.textBoxPasswort.Text) && this.textBoxPasswort.Text == this.textBoxPwdWh.Text) { Benutzer person = Benutzer.GetBenutzer(this.textBoxBenutzer.Text, null); //person.BenutzerName = this.textBoxBenutzer.Text; MD5 md5 = MD5.Create(); byte[] md5hash = md5.ComputeHash(Encoding.UTF8.GetBytes(this.textBoxPasswort.Text)); string pwdHash = string.Empty; foreach (byte b in md5hash) pwdHash += b.ToString("x2"); person.Passwort = pwdHash; if (person.Save() == 1) { this.groupBox1.Height = 100; this.labelPwdWh.Visible = false; this.textBoxPwdWh.Visible = false; this.buttonRegistrieren.Visible = false; this.textBoxPasswort.Text = this.textBoxPwdWh.Text = string.Empty; MessageBox.Show($"Benutzer {this.textBoxBenutzer.Text} wurde erfolgreich angelegt!", "Hinweis", MessageBoxButtons.OK, MessageBoxIcon.Information); this.buttonAnmelden.Enabled = true; } } } } }