diff --git a/PrototypWPFHAG/MainWindow.xaml b/PrototypWPFHAG/MainWindow.xaml
index 8e57ed9..6a87c50 100644
--- a/PrototypWPFHAG/MainWindow.xaml
+++ b/PrototypWPFHAG/MainWindow.xaml
@@ -25,7 +25,7 @@
-
+
diff --git a/PrototypWPFHAG/MainWindow.xaml.cs b/PrototypWPFHAG/MainWindow.xaml.cs
index 020e7b2..9528ac4 100644
--- a/PrototypWPFHAG/MainWindow.xaml.cs
+++ b/PrototypWPFHAG/MainWindow.xaml.cs
@@ -1,4 +1,6 @@
using System.Data;
+using System.Runtime.InteropServices;
+using System.Security.Principal;
using System.Text;
using System.Windows;
using System.Windows.Controls;
@@ -23,51 +25,11 @@ public partial class MainWindow : MetroWindow
public MainWindow()
{
InitializeComponent();
- // TestConnection();
- // Console.ReadKey();
+ //TestConnection();
+ //Console.ReadKey();
}
- private void loginButton_Click(object sender, RoutedEventArgs e)
- {
- // 从用户输入中获取用户名和密码
- string username = UsernameTextBox.Text; // 获取用户名
- string password = PasswordTextBox.Password; // 获取密码
-
- // 调用 ValidateUser 方法验证用户凭据
- if (ValidateUser(username, password))
- {
- MessageBox.Show("ok", "Login Successful", MessageBoxButton.OK, MessageBoxImage.Error);
-
- }
- else
- {
- // 如果验证失败,显示错误信息
- MessageBox.Show("Invalid username or password.", "Login Failed", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
-
- private bool ValidateUser(string username, string password)
- {
- // 获取数据库连接
- using (var con = GetConnection())
- {
- con.Open(); // 打开数据库连接
- string query = "SELECT COUNT(*) FROM USER WHERE UserName = @username AND Password = @password;";
-
- using (var cmd = new NpgsqlCommand(query, con))
- {
- // 使用参数化查询防止 SQL 注入
- cmd.Parameters.AddWithValue("@username", username);
- cmd.Parameters.AddWithValue("@password", password);
-
- // 执行查询并获取结果
- int count = (int)cmd.ExecuteScalar();
- return count > 0; // 如果匹配记录数量大于 0,返回 true
- }
- }
- }
-
private static void TestConnection()
{
using (NpgsqlConnection con = GetConnection())
@@ -81,7 +43,7 @@ public partial class MainWindow : MetroWindow
}
private static NpgsqlConnection GetConnection()
{
- return new NpgsqlConnection(@"Server=localhost;Port=5432;User Id=postgres;Password=postgres;Database=postgres;");
+ return new NpgsqlConnection(@"Server=localhost;Port=7854;User Id=postgres;Database=postgres;");
}
//class Program
diff --git a/PrototypWPFHAG/PrototypWPFHAG.csproj b/PrototypWPFHAG/PrototypWPFHAG.csproj
index 0db60b9..ac26644 100644
--- a/PrototypWPFHAG/PrototypWPFHAG.csproj
+++ b/PrototypWPFHAG/PrototypWPFHAG.csproj
@@ -24,7 +24,9 @@
+
+