Ejemplo n.º 1
0
        public ActionResult Login(User user)
        {
            string Encrypt(string text)
            {
                byte[] data = Encoding.UTF8.GetBytes(text);
                byte[] resultHash;
                SHA512 shaM = new SHA512Managed();

                resultHash = shaM.ComputeHash(data);
                StringBuilder result = new StringBuilder();

                for (int i = 0; i < resultHash.Length; i++)
                {
                    result.Append(resultHash[i].ToString("X2").ToLower());
                }
                return(result.ToString());
            }

            Classes.MongoDB db = new Classes.MongoDB();
            user.Password = Encrypt(user.Password);
            var usr = db.GetUser(user);

            if (usr != null)
            {
                Session["ScreenName"] = usr.ScreenName.ToString();
                Session["IsAdmin"]    = Convert.ToBoolean(usr.IsAdmin.ToString());
                return(RedirectToAction("../Home"));
            }
            else
            {
                ModelState.AddModelError("", "Username or Password Error");
            }
            return(View());
        }
Ejemplo n.º 2
0
        public void GetUser_Should_Return_User()
        {
            var db   = new Classes.MongoDB();
            var test = new User
            {
                ScreenName        = TEST_SCREEN_NAME,
                Email             = TEST_EMAIL,
                IsAdmin           = TEST_ISADMIN,
                Password          = TEST_PASSWORD,
                PasswordClearText = TEST_PASSWORD_CLEAR
            };
            var user = db.GetUser(test);

            Assert.IsNotNull(user);
        }