This repository has been archived on 2025-06-24. You can view files and clone it, but cannot push or open issues or pull requests.

104 lines
2.9 KiB
C#
Raw Normal View History

2025-03-19 10:04:16 +08:00
using System;
//using System.Collections.Generic;
2025-03-19 10:04:16 +08:00
using System.Globalization;
//using System.IO;
//using System.Linq;
2025-03-19 10:04:16 +08:00
using System.Security.Cryptography;
using System.Text;
//using System.Threading.Tasks;
2025-03-19 10:04:16 +08:00
using System.Windows;
//using System.Windows.Controls;
2025-03-19 10:04:16 +08:00
using System.Windows.Data;
//using System.Windows.Documents;
2025-03-19 10:04:16 +08:00
using System.Windows.Input;
using System.Windows.Media;
//using System.Windows.Media.Imaging;
//using System.Windows.Navigation;
//using System.Windows.Shapes;
2025-03-19 10:04:16 +08:00
2025-03-24 13:49:48 +08:00
namespace Karaoke_Kingpin.Controller
2025-03-19 10:04:16 +08:00
{
/// <summary>
/// MainWindow.xaml 的互動邏輯
/// </summary>
2025-04-01 10:31:05 +08:00
public partial class Login : Window
2025-03-19 10:04:16 +08:00
{
2025-04-01 10:31:05 +08:00
public Login()
2025-03-19 10:04:16 +08:00
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
AttemptLogin();
}
private void PasswordBox_KeyDown(object sender, KeyEventArgs e)
{
// 檢查是否按下 Enter 鍵
if (e.Key == Key.Enter)
{
AttemptLogin();
}
}
private void AttemptLogin()
{
string userName = txtUserName.Text;
string password = txtPassword.Text;
string hashedPassword = HashHelper.ComputeSha256Hash(password);
string storedHashedPassword = "05e8335be671f28dbeeca81756ee91c4c9aa3917fb6c50a326c2d58ce91bd6eb";
if (userName == "262622584" && hashedPassword == storedHashedPassword)
{
Index index = new Index();
index.Show();
this.Close();
}
else
{
MessageBox.Show("輸入用戶名或密碼不正確");
}
}
}
public static class HashHelper
{
public static string ComputeSha256Hash(string rawData)
{
// 使用SHA256
using (SHA256 sha256Hash = SHA256.Create())
{
// 计算输入字符串的哈希值
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(rawData));
// 将字节数组转换为字符串
StringBuilder builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
builder.Append(bytes[i].ToString("x2"));
}
return builder.ToString();
}
}
}
public class ColorToSolidColorBrushConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Color color)
{
return new SolidColorBrush(color);
}
return DependencyProperty.UnsetValue;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}