using Prism.Mvvm; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LampInspectionMachine.Model { public class Users : BindableBase { public Users() { } private int id; private Roles role= Roles.操作员; private string password; public int Id { get => id; set { SetProperty(ref id, value); } } public Roles Role { get => role; set { SetProperty(ref role, value); } } public string Password { get => password; set { SetProperty(ref password, value); } } public string CheckPwd(string pwd) { bool flag = false; StringBuilder pwdstr1 = new StringBuilder(); StringBuilder pwdstr2 = new StringBuilder(); for ( int i = 0; i < pwd.Length; i++ ) { if ( flag ) { pwdstr1.Append(pwd[ i ]); flag = false; } else { pwdstr2.Append(pwd[ i ]); flag = true; } } return pwdstr1.ToString() + pwdstr2.ToString(); } public bool CheckUserLogin(Users user, AppData appData) { Users users = new Users() { Id=0, Role= user.Role, Password=this.CheckPwd(user.Password), }; appData.CurrentUser = appData.DefaultUsers.Find(t => t.Role == users.Role && t.Password == users.Password); if ( appData.CurrentUser != null ) { return true; } return false; } } public enum Roles { 操作员, 工程师, 管理员 } }