public ActionResult Register(Register register)
        {
            if (ModelState.IsValid)
            {
                if (!String.Equals(register.User.PW, register.ConfirmPassword))
                {
                    ModelState.AddModelError("", "Password and confirm password does not match");
                    return View(register);
                }

                var user = db.Users.Where(e => e.UserName == register.User.UserName).FirstOrDefault();

                if (user != null)
                {
                    ModelState.AddModelError("", "Username already exists");
                    return View(register);
                }

                var userEmail = db.Users.Where(e => e.Email == register.Email).FirstOrDefault();

                if (userEmail != null)
                {
                    ModelState.AddModelError("", "Email already exists");
                    return View(register);
                }

                register.User.PW = Convert.ToBase64String(
                    new System.Security.Cryptography.SHA1CryptoServiceProvider().ComputeHash(
                        Encoding.ASCII.GetBytes(register.ConfirmPassword)));
                register.User.SignUpDateTime = DateTime.Now;
                register.User.Email = register.Email;
                register.User.Active = true;

                var newUser = register.User;

                db.Users.Add(newUser);
                db.SaveChanges();

                using (var mySmtp = new MySmtpClient())
                {
                    using (var message = new MyEmail(newUser.Email))
                    {
                        message.Subject = "Welcome to Crafty Losers!";
                        message.Body = "Welcome to Crafty Losers!  Good luck!";
                        mySmtp.Send(message);
                    }
                }

                IFormsAuthenticationService formsService = new FormsAuthenticationService();
                    formsService.SignIn(newUser.UserName, true);

            }
            else
            {
                return View(register);
            }

            return RedirectToAction("Index", "Home");
        }
        public ActionResult LogOn(LogOn logOn, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                logOn.User.PW = Convert.ToBase64String(
                    new System.Security.Cryptography.SHA1CryptoServiceProvider().ComputeHash(
                        Encoding.ASCII.GetBytes(logOn.User.PW)));

                var contextUser = db.Users.Where(e => e.UserName == logOn.User.UserName && e.PW == logOn.User.PW).FirstOrDefault();

                if (contextUser != null)
                {
                    IFormsAuthenticationService formsService = new FormsAuthenticationService();
                    formsService.SignIn(logOn.User.UserName, logOn.RememberMe);

                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            //return View(new LogOnViewModel(logOnModel));

            return View(new LogOn());
        }