Passwort verslüsselt
This commit is contained in:
+1
-1
@@ -29,7 +29,7 @@
|
|||||||
<Label Content="Name" Margin="0,30,0,0" FontSize="18" FontWeight="SemiBold" FontFamily="Palatino Linotype" Foreground="DarkGray"/>
|
<Label Content="Name" Margin="0,30,0,0" FontSize="18" FontWeight="SemiBold" FontFamily="Palatino Linotype" Foreground="DarkGray"/>
|
||||||
<TextBox x:Name="TxtName" Margin="0,0,0,30" Background="#BD9208"/>
|
<TextBox x:Name="TxtName" Margin="0,0,0,30" Background="#BD9208"/>
|
||||||
<Label Content="Passwort" FontSize="18" FontWeight="SemiBold" FontFamily="Palatino Linotype" Foreground="DarkGray"/>
|
<Label Content="Passwort" FontSize="18" FontWeight="SemiBold" FontFamily="Palatino Linotype" Foreground="DarkGray"/>
|
||||||
<TextBox x:Name="TxtPasswort" Margin="0,0,0,10" Background="#BD9208" />
|
<PasswordBox x:Name="TxtPasswort" Margin="0,0,0,10" Background="#BD9208" />
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
||||||
<Button Content="Anmelden" Width="80" Click="Anmelden_Click" Background="#BD9208" FontFamily="Palatino Linotype" FontWeight="SemiBold"/>
|
<Button Content="Anmelden" Width="80" Click="Anmelden_Click" Background="#BD9208" FontFamily="Palatino Linotype" FontWeight="SemiBold"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
+20
-2
@@ -14,6 +14,8 @@ using System.Windows.Media;
|
|||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using Mysqlx.Cursor;
|
using Mysqlx.Cursor;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
|
|
||||||
namespace Casino
|
namespace Casino
|
||||||
{
|
{
|
||||||
@@ -32,7 +34,7 @@ namespace Casino
|
|||||||
|
|
||||||
private void Anmelden_Click(object sender, RoutedEventArgs e)
|
private void Anmelden_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (checkLogin(TxtName.Text, TxtPasswort.Text))
|
if (checkLogin(TxtName.Text, TxtPasswort.Password))
|
||||||
{
|
{
|
||||||
|
|
||||||
MainWindow mainWindow = new MainWindow();
|
MainWindow mainWindow = new MainWindow();
|
||||||
@@ -51,11 +53,13 @@ namespace Casino
|
|||||||
Database db = new Database();
|
Database db = new Database();
|
||||||
ObservableCollection<User> users = new ObservableCollection<User>();
|
ObservableCollection<User> users = new ObservableCollection<User>();
|
||||||
users = db.GetUser();
|
users = db.GetUser();
|
||||||
|
string hash = HashPassword(passwort);
|
||||||
|
|
||||||
for (int i = 0; i < users.Count(); i++)
|
for (int i = 0; i < users.Count(); i++)
|
||||||
{
|
{
|
||||||
if (name.Equals(users[i].Name))
|
if (name.Equals(users[i].Name))
|
||||||
{
|
{
|
||||||
if(passwort.Equals(users[i].Passwort)) {
|
if(hash.Equals(users[i].Passwort)) {
|
||||||
MainWindow.currentUser = i;
|
MainWindow.currentUser = i;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -70,5 +74,19 @@ namespace Casino
|
|||||||
if (e.LeftButton == MouseButtonState.Pressed)
|
if (e.LeftButton == MouseButtonState.Pressed)
|
||||||
DragMove();
|
DragMove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public string HashPassword(string password)
|
||||||
|
{
|
||||||
|
using (SHA256 sha256 = SHA256.Create())
|
||||||
|
{
|
||||||
|
byte[] bytes = Encoding.UTF8.GetBytes(password);
|
||||||
|
byte[] hash = sha256.ComputeHash(bytes);
|
||||||
|
|
||||||
|
return Convert.ToHexString(hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user