Users.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Prism.Mvvm;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace LampInspectionMachine.Model
  8. {
  9. public class Users : BindableBase
  10. {
  11. public Users()
  12. {
  13. }
  14. private int id;
  15. private Roles role= Roles.操作员;
  16. private string password;
  17. public int Id { get => id; set { SetProperty(ref id, value); } }
  18. public Roles Role { get => role; set { SetProperty(ref role, value); } }
  19. public string Password { get => password; set { SetProperty(ref password, value); } }
  20. public string CheckPwd(string pwd)
  21. {
  22. bool flag = false;
  23. StringBuilder pwdstr1 = new StringBuilder();
  24. StringBuilder pwdstr2 = new StringBuilder();
  25. for ( int i = 0; i < pwd.Length; i++ )
  26. {
  27. if ( flag )
  28. {
  29. pwdstr1.Append(pwd[ i ]);
  30. flag = false;
  31. }
  32. else
  33. {
  34. pwdstr2.Append(pwd[ i ]);
  35. flag = true;
  36. }
  37. }
  38. return pwdstr1.ToString() + pwdstr2.ToString();
  39. }
  40. public bool CheckUserLogin(Users user, AppData appData)
  41. {
  42. Users users = new Users()
  43. {
  44. Id=0,
  45. Role= user.Role,
  46. Password=this.CheckPwd(user.Password),
  47. };
  48. appData.CurrentUser = appData.DefaultUsers.Find(t => t.Role == users.Role && t.Password == users.Password);
  49. if ( appData.CurrentUser != null )
  50. {
  51. return true;
  52. }
  53. return false;
  54. }
  55. }
  56. public enum Roles
  57. {
  58. 操作员,
  59. 工程师,
  60. 管理员
  61. }
  62. }