public static bool Authenticate(string userID, string password) { var actionType = "Login"; var actionData = "userID:" + userID; var success = false; Hanbo.Log.LogManager.Debug("Authenticate Start"); try { //取得User 資訊 var dc = new SDMSDataContext(); var user = dc.UserMember.SingleOrDefault(p => p.UserID == userID && p.Disabled == false); if (user != null) { // salt var encodePassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password + user.Salt, "SHA1"); success = encodePassword == user.Password; if (success) { _userID = user.UserID; _loginTime = DateTime.Now; } } //ActionLog var userLoginLog = dc.ActionLog.Where(p => p.UserID == userID && p.ActionType == "Login" && p.Note != "Fail") .OrderByDescending(p => p.CreateOn) .Take(1).SingleOrDefault(); if (userLoginLog != null) _lastLoginTime = userLoginLog.CreateOn; var acLog = new ActionLog() { ActionType = actionType, ActionData = actionData, UserID = GetUserID(), CreateOn = DateTime.Now, Note = (success) ? "Success" : "Fail", }; dc.ActionLog.InsertOnSubmit(acLog); dc.SubmitChanges(); } catch (Exception ex) { Hanbo.Log.LogManager.Debug(ex.Message); } Hanbo.Log.LogManager.Debug("Authenticate Done"); return success; }
partial void UpdateActionLog(ActionLog instance);
partial void DeleteActionLog(ActionLog instance);
partial void InsertActionLog(ActionLog instance);