94 lines
2.9 KiB
C#
94 lines
2.9 KiB
C#
using System;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using MySql.Data.MySqlClient;
|
|
using BCrypt.Net;
|
|
|
|
namespace SkyTeam
|
|
{
|
|
public partial class LogInPage : Page
|
|
{
|
|
public LogInPage()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void AdminLink_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (Application.Current.MainWindow is MainWindow mainWindow)
|
|
{
|
|
mainWindow.MainFrame.Navigate(new AdminLoginPage());
|
|
}
|
|
}
|
|
|
|
|
|
private void LogInButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
string email = BenutzernameTextBox.Text;
|
|
string password = PasswortTextBox.Password;
|
|
|
|
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
|
|
{
|
|
MessageBox.Show("Bitte Email und Passwort eingeben.");
|
|
return;
|
|
}
|
|
|
|
string query = @"
|
|
SELECT Id, Vorname, Rolle, PasswortHash
|
|
FROM users
|
|
WHERE Email = @email";
|
|
|
|
try
|
|
{
|
|
using (MySqlConnection conn = new MySqlConnection(DatenbankServices.GetConnection()))
|
|
{
|
|
conn.Open();
|
|
|
|
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
|
{
|
|
cmd.Parameters.AddWithValue("@email", email);
|
|
|
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
if (!reader.Read())
|
|
{
|
|
MessageBox.Show("Benutzer wurde nicht gefunden.");
|
|
return;
|
|
}
|
|
|
|
string storedHash = reader.GetString("PasswortHash");
|
|
|
|
if (!BCrypt.Net.BCrypt.Verify(password, storedHash))
|
|
{
|
|
MessageBox.Show("Falsches Passwort.");
|
|
return;
|
|
}
|
|
|
|
|
|
SessionManager.CurrentUserId = reader.GetInt32("Id");
|
|
SessionManager.CurrentUserName = reader.GetString("Vorname");
|
|
SessionManager.Role = reader.GetString("Rolle");
|
|
}
|
|
}
|
|
|
|
|
|
((MainWindow)Application.Current.MainWindow)
|
|
.MainFrame.Navigate(new NavigationPage());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show("Datenbankfehler: " + ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void anmeldungsButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
((MainWindow)Application.Current.MainWindow)
|
|
.MainFrame.Navigate(new RegistrationPage());
|
|
}
|
|
}
|
|
}
|