public LoginMessage AuthenticateAccount(string site, string device, string deviceId, string sessionId, string account, string password) { LoginMessage msg = new LoginMessage(); var user = repoUser.Query(o => o.Account == account && o.Status == DataStatus.Normal).FirstOrDefault(); if (user == null) { msg.Status = LoginStatus.AccountNotExists; return(msg); } password = pwdEncrypt.Encrypt(password); if (user.Password != password) { msg.Status = LoginStatus.PasswordNotCorrect; return(msg); } var siteInfo = host.GetSites().GetSiteByName(site); if (siteInfo == null) { msg.Status = LoginStatus.Exception; msg.Message = string.Format("Site {0} is not found.", site); return(msg); } string token = generator.Generate(RandomChars, AccessTokenLength); var session = repoSession.Query(o => o.SessionId == sessionId).FirstOrDefault(); if (session == null) { session = new ServerSession() { SessionId = sessionId, SiteName = site, UserId = user.UserId, Device = device, DeviceId = deviceId, AccessToken = token, AccessTokenExpiryTime = DateTime.Now.AddMinutes(SessionTimeOutMinutes), LastAccessTime = DateTime.Now }; repoSession.Insert(session); } else { session.AccessToken = token; session.UserId = user.UserId; session.AccessTokenExpiryTime = DateTime.Now.AddMinutes(SessionTimeOutMinutes); session.LastAccessTime = DateTime.Now; repoSession.Update(session); } msg.Status = LoginStatus.Success; msg.EncryptedSession = GetEncryptedLocalSession(siteInfo, user, session); return(msg); }