Login.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace Welling_Motor_Debug_Tool
  12. {
  13. public partial class Login : Form
  14. {
  15. LocalInfo localInfo = new LocalInfo();
  16. public Login()
  17. {
  18. InitializeComponent();
  19. }
  20. public Dictionary<string, string> UserAccount = new Dictionary<string, string>();
  21. private void Login_Load(object sender, EventArgs e)
  22. {
  23. UserAccount.Clear();
  24. //读取账户信息
  25. try
  26. {
  27. //检查配置文件
  28. if (!Directory.Exists(localInfo.LocalPath))
  29. Directory.CreateDirectory(localInfo.LocalPath);
  30. if (!File.Exists(localInfo.LocalPath+localInfo.UsrFileName))
  31. {
  32. //设定账户密码
  33. string info = "";
  34. info += "USER=中置量产写入,PASSWD=1;";
  35. info += "USER=中置量产检验,PASSWD=2;";
  36. info += "USER=轮毂量产写入,PASSWD=3;";
  37. info += "USER=轮毂量产检验,PASSWD=4;";
  38. info += "USER=中置样机测试,PASSWD=5;";
  39. info += "USER=轮毂样机测试,PASSWD=6;";
  40. info += "USER=FCT治具测试,PASSWD=7;";
  41. info += "USER=工程参数配置,PASSWD=123456;";
  42. info += "USER=研发调试,PASSWD=123456;";
  43. info += "USER=管理员,PASSWD=ttium.123";
  44. //加密保存
  45. aes.EncryptToFile(info, localInfo.LocalPath + localInfo.UsrFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  46. }
  47. //解密
  48. string decryptedText = aes.DecryptFromFile(localInfo.LocalPath + localInfo.UsrFileName, "2D820F88F60A39D5", "3687C5216B19D16B");
  49. //获取账号
  50. string[] userInfo = decryptedText.Split(';');
  51. foreach (string info in userInfo)
  52. {
  53. if (info != null)
  54. {
  55. UserAccount.Add(info.Split(',')[0].Split('=')[1], info.Split(',')[1].Split('=')[1]);
  56. }
  57. }
  58. }
  59. catch (System.Exception)
  60. {
  61. MessageBox.Show("无账户信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  62. UserAccount.Add("未知用户", "");
  63. }
  64. //账户名下拉列表更新
  65. comboBox_User.Items.Clear();
  66. foreach (string key in UserAccount.Keys)
  67. {
  68. comboBox_User.Items.Add(key);
  69. }
  70. //密码框清空
  71. textBox_Passwd.Text = "";
  72. }
  73. private void button_Login_Click(object sender, EventArgs e)
  74. {
  75. this.Close();
  76. }
  77. private void button_keyboard_Click(object sender, EventArgs e)
  78. {
  79. System.Diagnostics.Process.Start("osk.exe");
  80. }
  81. private void textBox_Passwd_KeyUp(object sender, KeyEventArgs e)
  82. {
  83. if (e.KeyCode == Keys.Enter)
  84. this.Close();
  85. }
  86. private void comboBox_User_SelectedIndexChanged(object sender, EventArgs e)
  87. {
  88. }
  89. private void label1_Click(object sender, EventArgs e)
  90. {
  91. }
  92. }
  93. }