MVC 5 login and sign page taking the value from dataabase
in login and registration page how do i store the value in database and take the login value from database in mvc 5
10 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Arunprasath Gajapathi49 pointsPosted Apr 16, 2017, 12:22 AM EDT
Shahbaz KawareRank #3,236 · 439 pointsPosted Apr 16, 2017, 12:51 AM EDT
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return View(model); } // Require the user to have a confirmed email before they can log on. var user = await UserManager.FindByNameAsync(model.Email); if (user != null) { if (!await UserManager.IsEmailConfirmedAsync(user.Id)) { string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account-Resend"); ViewBag.errorMessage = "You must have a confirmed email to log on."; return View("Error"); } } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: true); switch (result) { case SignInStatus.Success: return RedirectToLocal(returnUrl); case SignInStatus.LockedOut: return View("Lockout"); case SignInStatus.RequiresVerification: return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return View(model); }public bool Login(LoginViewModel login) { string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand("Login", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Email", login.Email); cmd.Parameters.AddWithValue("@Password", login.Password); con.Open(); int i = cmd.ExecuteNonQuery(); con.Close(); if (i >= 1) { return true; } else { return false; } }Arunprasath Gajapathi49 pointsPosted Apr 16, 2017, 1:00 AM EDT
public async Task Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return View(model); } using(YourDBContext=new YourDBContext()) { var LoggedInUserDetails=YourDBContext.Users.FirstOrDefualt(user=>user.Emai.Equals(model.Email) && user.Password.Equals(model.Password)); if( LoggedInUserDetails!=null) { //redirect to your home page } else ModelState.AddModelError("", "Invalid login attempt."); } return View(model); } try this.Shahbaz KawareRank #3,236 · 439 pointsPosted Apr 16, 2017, 1:04 AM EDT
Arunprasath Gajapathi49 pointsPosted Apr 16, 2017, 1:04 AM EDT
Shahbaz KawareRank #3,236 · 439 pointsPosted Apr 16, 2017, 1:14 AM EDT
Arunprasath Gajapathi49 pointsPosted Apr 16, 2017, 1:18 AM EDT
using(var YourDBConext=new YourDBContext()) { } try like thisShahbaz KawareRank #3,236 · 439 pointsPosted Apr 16, 2017, 1:20 AM EDT
Arunprasath Gajapathi49 pointsPosted Apr 16, 2017, 2:15 AM EDT
Shahbaz KawareRank #3,236 · 439 pointsPosted Apr 16, 2017, 2:17 AM EDT