schangxiang@126.com
2025-11-04 f5ed29dc26c7cd952d56ec5721a2efc43cd25992
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using XImagingXhandler.XDAL;
using XHandler.Class;
using DataEntity.Share;
 
namespace XHandler
{
    /// <summary>
    /// LoginWindow.xaml 的交互逻辑
    /// </summary>
    public partial class LoginWindow : Window
    {
        public LoginWindow()
        {
            InitializeComponent();
        }
 
        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
 
        private void LoginUser_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (!string.IsNullOrEmpty(LoginUser.Text.Trim()))
            {
                LoginUser.BorderThickness = new Thickness(0, 0, 0, 0);
                LoginUserTips.Visibility = Visibility.Collapsed;
            }
        }
 
        private void LoginPassword_PasswordChanged(object sender, RoutedEventArgs e)
        {
            if (LoginPassword.Password.Length <= 0)
            {
                pawdHintText.Text = Properties.Resources.strPassword;
                //okBtn.IsEnabled = false;
            }
            else
            {
                pawdHintText.Text = "";
                LoginPassword.BorderThickness = new Thickness(0, 0, 0, 0);
                LoginPasswordTips.Visibility = Visibility.Collapsed;
            }
 
        }
 
        private void btnLogin_Click_1(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(LoginUser.Text.Trim()))
            {
                LoginUser.BorderThickness = new Thickness(1, 1, 1, 1);
                LoginUserTips.Content = Properties.Resources.strPlsInputUsername;
                LoginUserTips.Visibility = Visibility.Visible;
                return;
            }
 
            if (string.IsNullOrEmpty(LoginPassword.Password.Trim()))
            {
                LoginPassword.BorderThickness = new Thickness(1, 1, 1, 1);
                LoginPasswordTips.Content = Properties.Resources.strPlsInputPassword;
                LoginPasswordTips.Visibility = Visibility.Visible;
                return;
            }
 
            string user = LoginUser.Text.Trim();
            string pswd = LoginPassword.Password.Trim();
            string md5pswd = GetMD5(pswd);
            bool isAuthor = true;// IsAuthority.IsAuthorityDog();
            if (isAuthor)
            {
                bool ok = UserDB.isExistUserByUserInfo(user, md5pswd);
                if (ok)
                {
                    Shared.User = UserDB.GetUserInfByUserName(user);
                    MainWindow mainWindow = new MainWindow();
                    mainWindow.Show();
                    this.Close();
                }
            }
            else
            {
                MessageBoxResult messageBoxResult = MessageBox.Show("请检查加密狗后再试!", "Error", MessageBoxButton.OK);
            }
        }
 
        public static string GetMD5(string password)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] bytValue, bytHash;
            bytValue = System.Text.Encoding.UTF8.GetBytes(password);
            bytHash = md5.ComputeHash(bytValue);
            md5.Clear();
            string sTemp = "";
            for (int i = 0; i < bytHash.Length; i++)
            {
                sTemp += bytHash[i].ToString("X").PadLeft(2, '0');
            }
            return sTemp.ToLower();
        }
 
        private void LoginPassword_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                btnLogin_Click_1(this, null);
            }
        }
    }
}