private void Name_LostFocus(object sender, RoutedEventArgs e) { //获取文本框的值 string Name = UserName.Text; Auther AutherTemp = authDAO.GetByName(Name); if (AutherTemp != null) { MessageBoxX.Info(LanguageUtils.ConvertLanguage("用户名已存在", "The username has already existed")); } }
/// <summary> /// 登录 /// </summary> /// <returns></returns> public string Login(string username, string password) { string loginResult = "success"; AuthDAO authDAO = new AuthDAO(); //先验证admin Auther auther = authDAO.Login(username, password); //超管监测权限 if (auther != null && auther.Auth_Level == Auther.AUTH_LEVEL_ADMIN) { loginResult = "check_U"; return(loginResult); } Auther autherCN = authDAO.GetByName(username); //密码错误 if (autherCN == null) { loginResult = "没有该用户"; return(loginResult); } //没有该用户 if (autherCN != null && auther == null) { loginResult = "密码错误!"; return(loginResult); } //普通用户测试是否超时登录 if (auther.Auth_OfflineTime < DateTime.Now) { loginResult = "您的使用时间已经用尽,请联系宝德龙管理员"; return(loginResult); } //登录mac与激活mac不对应 SetterDAO setterDAO = new SetterDAO(); Setter setter = setterDAO.getSetter(); string mac = ""; try { byte[] debytes = AesUtil.Decrypt(Encoding.GetEncoding("GBK").GetBytes(setter.Set_Unique_Id), ProtocolConstant.USB_DOG_PASSWORD); mac = Encoding.GetEncoding("GBK").GetString(debytes); //byte[] a = ProtocolUtil.StringToBcd(setter.Set_Unique_Id); //byte[] b = AesUtil.Decrypt(a, ProtocolConstant.USB_DOG_PASSWORD); //mac = Encoding.GetEncoding("GBK").GetString(b); } catch (Exception ex) { //解密出现问题,经常会报错,目前是直接返回的登陆成功的信息。 logger.Error("解密异常:" + ex.Message); //Console.WriteLine("解密异常:" + ex.Message); //loginResult = "解密异常."; //return loginResult; } //如果解密后的setter中的mac不包含现在获得的mac if (mac.IndexOf(SystemInfo.GetMacAddress().Replace(":", "-")) == -1) { //Console.WriteLine("DB:"+ mac); //Console.WriteLine("current:" + SystemInfo.GetMacAddress().Replace(":","-")); //loginResult = "登录异常"; //return loginResult; logger.Error("机器码匹配异常," + DateTime.Now.ToString()); } if (autherCN.User_Status == Auther.USER_STATUS_FREEZE) { loginResult = "用户已被冻结"; return(loginResult); } return(loginResult); }