Beispiel #1
0
    public static void Log(string Message, string Code = "", string Page = "")
    {
        try
        {
            string    file     = HttpContext.Current.Server.MapPath("~/App_Data/ErrorLog.xml");
            XDocument errorLog = XDocument.Load(file);
            if (string.IsNullOrEmpty(Code))
            {
                Code = HttpContext.Current.Response.StatusCode.ToString();
            }
            if (string.IsNullOrEmpty(Page))
            {
                Page = HttpContext.Current.Request.Url.AbsolutePath.ToString();
            }

            errorLog.Root.Add(new XElement("log", new XAttribute("code", Code),
                                           new XAttribute("message", Message),
                                           new XAttribute("datetime", DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString()),
                                           new XAttribute("page", Page),
                                           new XAttribute("ip", AppUtility.GetUserIPAddress())));
            errorLog.Save(file);
        }
        catch (Exception ex)
        {
            string msg = ex.Message;
        }
    }
Beispiel #2
0
        public bool Authenticate(string Email, string Passkey)
        {
            using (var db = new MemberLiteEntities().Init)
            {
                var u = db.Users.Select(a => new
                {
                    a.UserID,
                    a.FirstName,
                    a.Email,
                    a.Password,
                    a.Status
                })
                        .Where(a => a.Email == Email)
                        .FirstOrDefault();
                if (u == null)
                {
                    ReturnMessage = "Invalid login or password! Check and try again";
                    return(false);
                }

                string userIDHash = Crypto.SHA256Hash(u.UserID);
                string pwdHash    = Crypto.SHA256Hash(Passkey.ToUpper());
                string finalHash  = Crypto.SHA256Hash(userIDHash + pwdHash);

                if (finalHash == u.Password)
                {
                    //Check account status
                    var status = (StatusType)u.Status;
                    if (status == StatusType.Locked)
                    {
                        if (LockoutReleaseDate.HasValue)
                        {
                            //perform lock action
                        }

                        ReturnMessage = "Your account is locked!";
                        return(false);
                    }
                    else if (status == StatusType.Banned)
                    {
                        ReturnMessage = "You have been banned!";
                        return(false);
                    }

                    this.UserID = u.UserID;

                    //Log login history
                    db.LoginHistory.Add(new LoginHistory
                    {
                        UserID     = u.UserID,
                        IP         = AppUtility.GetUserIPAddress(),
                        DeviceType = AppUtility.GetDeviceType(),
                        DateStamp  = DateTime.Now,
                        UserAgent  = HttpContext.Current.Request.Browser.Browser
                    });
                    db.SaveChanges();

                    ReturnMessage = "Login ok!";
                    return(true);
                }
                else
                {
                    ReturnMessage = "Invalid login or password! Check and try again.";
                    return(false);
                }
            }
        }