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 { /// /// LoginWindow.xaml 的交互逻辑 /// 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); } } } }