Example #1
0
        public ActionResult ChangePassword(RegisterModel model)
        {
            if (model.Password != model.ConfirmPassword)
            {
                return RedirectToAction("ChangePassword", "Account");
            }

            var data = Encoding.ASCII.GetBytes(model.Password);
            var md5 = new MD5CryptoServiceProvider();
            md5.ComputeHash(data);
            byte[] md5data = md5.Hash;
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < md5data.Length; i++)
            {
                sb.Append(md5data[i].ToString("x2"));
            }
            string hashPassword = sb.ToString();

            var user = _bookieContext.Users.FirstOrDefault(x => x.Username == User.Identity.Name);
            user.Password = hashPassword;
            _bookieContext.SaveChanges();
            return RedirectToAction("Index", "Home");
        }
Example #2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                BookieDatabase.Users userPf = new BookieDatabase.Users();
                userPf.Username = model.UserName;
                userPf.Password = model.Password;
                var result = CrateUser(userPf);
                //var result = await UserManager.CreateAsync(user, model.Password);
                if (result.ToLower() == "success")
                {
                    //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    ViewBag.newUser = model;
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return View("Index");
                }
                List<string> errors = new List<string>();
                ViewBag.Erros = errors;
            }

            // If we got this far, something failed, redisplay form

            return View(model);
        }