public static bool DoLogin(string userName, string password)
        {
            PwsDbContext db = new PwsDbContext();

            // Cek apakah pengguna berhak untuk login atau tidak
            if (db.Users.Where(x => x.LoginName == userName && x.LoginPassword == password && x.Activate == true).Count() == 1)
            {
                // User berhak login, lakukan penulisan data pada sesi
                HttpContext.Current.Session["sessdata"] = new SessionData {
                    CheckingString = "hanahbanana", UserName = userName, IsAdmin = false
                };

                // Catatkan Lastlogin pada tabel user
                db.Users.SingleOrDefault(x => x.LoginName == userName).LastLogin = DateTime.Now;
                db.SaveChanges();

                return(true);
            }
            else if (db.Admins.Where(x => x.AdminName == userName && x.Password == password).Count() == 1)
            {
                HttpContext.Current.Session["sessdata"] = new SessionData {
                    CheckingString = "hanahbanana", UserName = userName, IsAdmin = true
                };
                return(true);
            }

            return(false);
        }
Example #2
0
        public static bool DoLogin(string userName, string password)
        {
            PwsDbContext db = new PwsDbContext();

            // Cek apakah pengguna berhak untuk login atau tidak
            if (db.Users.Where(x => x.LoginName == userName && x.LoginPassword == password).Count() == 1)
            {
                // User berhak login, lakukan penulisan data pada sesi
                HttpContext.Current.Session["sessdata"] = new SessionData {
                    CheckingString = "hanahbanana", UserName = userName
                };
                return(true);
            }

            return(false);
        }