public IActionResult RegisterLoginModel(RegisterLoginModel registerLoginModel) { var user = new User(); Cryptography cryptography = new Cryptography(System.Security.Cryptography.MD5.Create()); //Verifica se email existe if (UserEmailExists(registerLoginModel.Email)) { ModelState.AddModelError("Email", "O e-mail inserido já existe"); } //Verifica se a senha a confirmação de senha são iguais if (!cryptography.HashVerify(registerLoginModel.PasswordConfirm, registerLoginModel.Password)) { ModelState.AddModelError("Password", "A senha e a confirmação de senha não são iguais"); } //Verifica força da senha else if (user.VerifyPasswordStrong(registerLoginModel.Password) < 3) { ModelState.AddModelError("Password", "A segurança da senha é baixa"); } if (ModelState.IsValid) { user.Name = registerLoginModel.Name.ToUpper(); user.Email = registerLoginModel.Email.ToUpper(); user.Password = cryptography.HashGenerate(registerLoginModel.Password); TempData["RegisterUser"] = JsonConvert.SerializeObject(user); return(RedirectToAction(nameof(RegisterInformationModel))); } registerLoginModel.Password = null; registerLoginModel.PasswordConfirm = null; return(View(registerLoginModel)); }
public async Task <IActionResult> Login(RegisterLoginModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set lockoutOnFailure: true var result = await _signInManager.PasswordSignInAsync(model.LoginModel.UserName, model.LoginModel.Password, model.LoginModel.RememberMe, lockoutOnFailure : false); if (result.Succeeded) { _logger.LogInformation("User logged in."); return(RedirectToLocal(returnUrl)); } if (result.RequiresTwoFactor) { return(RedirectToAction(nameof(LoginWith2fa), new { returnUrl, model.LoginModel.RememberMe })); } if (result.IsLockedOut) { _logger.LogWarning("User account locked out."); return(RedirectToAction(nameof(Lockout))); } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(View(model)); } } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> Register(RegisterLoginModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.RegisterModel.UserName, PhoneNumber = model.RegisterModel.PhoneNumber, Email = model.RegisterModel.Email }; var result = await _userManager.CreateAsync(user, model.RegisterModel.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); await _emailSender.SendEmailConfirmationAsync(model.RegisterModel.Email, callbackUrl); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Register(RegisterLoginModel model) { databaseContext.Users.Add(new User() { email = model.email, password = model.password }); databaseContext.SaveChanges(); return(RedirectToAction("Login")); }
public ActionResult Login(RegisterLoginModel model) { User user = databaseContext.Users.Where(x => x.email == model.email && x.password == model.password).FirstOrDefault(); if (user != null) { Session["session"] = user.email; } else { TempData["Hata"] = "Email veya şifre hatalı"; return(View()); } return(RedirectToAction("Index", "Home")); }