Пример #1
0
        public ActionResult Index(LoginAccount loginAccount)
        {
            if (ModelState.IsValid)
            {
                // todo: If the loginAccount object is valid
                // Compare to see if the object exists in the database
                Catalogue.Models.CatalogueDBEntities database = new Models.CatalogueDBEntities();

                if (database.Database.Exists())
                {
                    foreach (Models.User user in database.Users)
                    {
                        if (string.Compare(user.UserName.ToLower(), loginAccount.UserName.ToLower()) == 0)
                        {
                            SHA512 encryption = new SHA512Managed();
                            byte[] data       = new byte[loginAccount.Password.Length];
                            byte[] result;
                            string temp = loginAccount.Password;

                            for (int i = 0; i < loginAccount.Password.Length; i++)
                            {
                                data[i] = (byte)loginAccount.Password[i];
                            }

                            result = encryption.ComputeHash(data);

                            string newString = "";

                            for (int i = 0; i < result.Length; i++)
                            {
                                newString += String.Format("{0:X2}", result[i]);
                            }

                            loginAccount.Password = newString;

                            if (string.Compare(user.Password, loginAccount.Password) == 0)
                            {
                                Session["Login"]  = user.UserName;
                                Session["UserID"] = user.UserID;
                                return(RedirectToAction("Index", "Home"));
                            }

                            loginAccount.Password = temp;
                        }
                    }
                }
            }

            ViewBag.Error = "Invalid Login / Password";

            return(View(loginAccount));
        }
Пример #2
0
        public ActionResult Index(LoginAccount loginAccount)
        {
            if (ModelState.IsValid)
            {
                // todo: If the loginAccount object is valid
                // Compare to see if the object exists in the database
                Catalogue.Models.CatalogueDBEntities database = new Models.CatalogueDBEntities();

                if (database.Database.Exists())
                {
                    foreach( Models.User user in database.Users)
                    {
                        if(string.Compare(user.UserName.ToLower(), loginAccount.UserName.ToLower()) == 0)
                        {
                            SHA512 encryption = new SHA512Managed();
                            byte[] data = new byte[loginAccount.Password.Length];
                            byte[] result;
                            string temp = loginAccount.Password;

                            for (int i = 0; i < loginAccount.Password.Length; i++)
                                data[i] = (byte)loginAccount.Password[i];

                            result = encryption.ComputeHash(data);

                            string newString = "";

                            for (int i = 0; i < result.Length; i++)
                                newString += String.Format("{0:X2}", result[i]);

                            loginAccount.Password = newString;

                            if (string.Compare(user.Password, loginAccount.Password) == 0)
                            {
                                Session["Login"] = user.UserName;
                                Session["UserID"] = user.UserID;
                                return RedirectToAction("Index", "Home");
                            }

                            loginAccount.Password = temp;
                        }
                    }
                }
            }

            ViewBag.Error = "Invalid Login / Password";

            return View(loginAccount);
        }
Пример #3
0
        // GET: Login
        public ActionResult Index()
        {
            LoginAccount loginAccount = new LoginAccount();

            return(View(loginAccount));
        }
Пример #4
0
        // GET: Login
        public ActionResult Index()
        {
            LoginAccount loginAccount = new LoginAccount();

            return View(loginAccount);
        }