Ejemplo n.º 1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            ViewBag.HasError = false;
            if (UnitOfWork <UserManager>().IsExistingEmail(model.Email))
            {
                ModelState.AddModelError("", ControllerResources.AccountController_Register_An_account_with_this_email_already_exists_);
            }
            if (ModelState.IsValid)
            {
                // let's user refine this in the profile
                var user = new User {
                    UserName         = model.UserName,
                    Email            = model.Email,
                    Password         = TexxtoorMembershipService.CreateHash(model.Password, TexxtoorMembershipService.HashAlgorithmType),
                    PhoneNumber      = model.Phone,
                    PasswordQuestion = model.PasswordQuestion,
                    PasswordAnswer   = model.PasswordAnswer,
                    PasswordFormat   = MembershipPasswordFormat.Hashed
                };
                var result = await UnitOfWork <UserManager>().Usermanager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    user.SecurityStamp = Guid.NewGuid().ToString();
                    await UnitOfWork <UserManager>().SignInAsync(user, false);

                    UnitOfWork <UserManager>().LogSignIn(model.UserName, true);
                    return(RedirectToAction("WelcomeNewUser", model));
                }
                ViewBag.Status = TexxtoorMembershipService.ErrorCodesToString(result.Errors);
            }
            // If we got this far, something failed, redisplay form
            ViewBag.HasError       = true;
            ViewBag.PasswordLength = UnitOfWork <UserManager>().MinPasswordLength;
            return(View(model));
        }
Ejemplo n.º 2
0
        public override PasswordVerificationResult VerifyHashedPassword(string hashedPassword, string providedPassword)
        {
            var testHash = TexxtoorMembershipService.CreateHash(providedPassword, FormsAuthPasswordFormat);

            return(hashedPassword.Equals(testHash) ? PasswordVerificationResult.Success : PasswordVerificationResult.Failed);
        }
Ejemplo n.º 3
0
 public override string HashPassword(string password)
 {
     return(TexxtoorMembershipService.CreateHash(password, FormsAuthPasswordFormat));
 }