Guest User

Untitled

a guest
Apr 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. [AcceptVerbs(HttpVerbs.Post)]
  2. public ActionResult Login(FormCollection collection)
  3. {
  4. var users =
  5. (from p in _dataContext.Users
  6. where p.Name == collection["Username"] && p.Password == collection["Password"]
  7. select p);
  8.  
  9. if (users.Count() > 0)
  10. {
  11. // Login Succeed
  12. // To get the username I should do something like users.First().Name
  13. // and that's really bad...
  14.  
  15. return RedirectToAction("Login");
  16. }
  17. else
  18. {
  19. // Login Faild
  20. return View();
  21. }
  22. }
  23.  
  24. var user = _dataContext.Users.SingleOrDefault(p =>
  25. p.Name == collection["Username"]
  26. && p.Password == collection["Password"]);
  27.  
  28. if(user != null)
  29. {
  30. // Go on...
  31. return RedirectToAction("Login");
  32. }
  33. else
  34. {
  35. // Login Faild
  36. return View();
Add Comment
Please, Sign In to add comment