コード例 #1
0
        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;
        }
コード例 #2
0
 partial void UpdateActionLog(ActionLog instance);
コード例 #3
0
 partial void DeleteActionLog(ActionLog instance);
コード例 #4
0
 partial void InsertActionLog(ActionLog instance);