Exemplo n.º 1
0
        public void AddValidFaileHistory(string logonName, string cryptPwd, string ipAddress)
        {
            var lastSuccess = Ctx.tbl_UserLogonHistory.Where(m => m.IPAddress == ipAddress && m.Password == null).OrderByDescending(m => m.LogonDate).FirstOrDefault();

            MD.tbl_UserLogonHistory logonHistory = Ctx.tbl_UserLogonHistory.Where(md => md.LogonName == logonName && md.IPAddress == ipAddress &&
                                                                                  md.Password != null &&
                                                                                  SqlFunctions.DateAdd("mi", 20, md.LogonDate) > DateTime.Now).OrderByDescending(md => md.LogonDate).FirstOrDefault();
            if (logonHistory == null || (lastSuccess != null && lastSuccess.ID > logonHistory.ID)) // 登录成功过,应忽略20分钟的条件,新增一条记录
            {
                logonHistory            = new MD.tbl_UserLogonHistory();
                logonHistory.IPAddress  = ipAddress;
                logonHistory.LogonName  = logonName;
                logonHistory.Password   = cryptPwd;
                logonHistory.LogonTimes = 1;
                logonHistory.LogonDate  = DateTime.Now;
                Ctx.tbl_UserLogonHistory.Add(logonHistory);
            }
            else
            {
                logonHistory.Password   = cryptPwd;
                logonHistory.LogonTimes = logonHistory.LogonTimes + 1;
                logonHistory.LogonDate  = DateTime.Now;
            }
            Ctx.SaveChanges();
        }
Exemplo n.º 2
0
 public void AddValidSuccessHistory(string logonName, string cryptPwd, string ipAddress)
 {
     MD.tbl_UserLogonHistory logonHistory = new MD.tbl_UserLogonHistory();
     logonHistory.IPAddress  = ipAddress;
     logonHistory.LogonName  = logonName;
     logonHistory.LogonTimes = 1;
     logonHistory.LogonDate  = DateTime.Now;
     Ctx.tbl_UserLogonHistory.Add(logonHistory);
     Ctx.SaveChanges();
 }