Advertisement
Guest User

Untitled

a guest
May 28th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. [HttpPost]
  2. public ActionResult LogOn(LogOnModel model, string returnUrl)
  3. { if (ModelState.IsValid)
  4. {
  5.  
  6. bool pass = true;
  7. // aqui verifica se tem espaço ou caracteres ilegais
  8. foreach (var item in model.UserName)
  9. {
  10. if (!char.IsLetterOrDigit(item))
  11. {
  12. pass = false;
  13. ModelState.AddModelError("", "O nome de usuário ou senha fornecida está incorreta.");
  14. }
  15. }
  16. // aqui verifica se tem espaço ou caracteres ilegais
  17. foreach (var item in model.Password)
  18. {
  19. if (!char.IsLetterOrDigit(item))
  20. {
  21. pass = false;
  22. ModelState.AddModelError("", "O nome de usuário ou senha fornecida está incorreta.");
  23. }
  24. }
  25.  
  26.  
  27. if (pass)
  28. {
  29. // se não houver caracteres ilegais valida o login
  30. if (MembershipService.ValidateUser(model.UserName, model.Password))
  31. {
  32. FormsService.SignIn(model.UserName, false);
  33. if (!String.IsNullOrEmpty(returnUrl))
  34. {
  35. return Redirect(returnUrl);
  36. }
  37. else
  38. {
  39.  
  40. return RedirectToAction("Index", "Home");
  41. }
  42. }
  43. else
  44. {
  45. ModelState.AddModelError("", "O nome de usuário ou senha fornecida está incorreta.");
  46. }
  47. }
  48.  
  49. }
  50.  
  51. return View(model);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement