Created
March 22, 2013 01:36
-
-
Save ChaseFlorell/5218298 to your computer and use it in GitHub Desktop.
Specifically for StackOverflow Question - http://stackoverflow.com/q/15560855/124069
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ActionResult LogOn(LogOnModel model, string returnUrl) | |
{ | |
// check if a valid user was selected | |
var user = GetuserByname(model.UserName); | |
if (user.ToList().Count != 1) | |
{ | |
ModelState.AddModelError("Username", "Username is invalid"); | |
} | |
var dbPassword = user.First().UserPassword.ToString().Trim(); | |
var enterPassword = CreatePasswordHash(model.Password, user.First().Salt.ToString().Trim()); | |
if (dbPassword != enterPassword) | |
{ | |
ModelState.AddModelError("dbPassword", "Password is invalid"); | |
} | |
if (!ModelState.IsValid) { | |
return View(model); | |
} | |
FormsAuthentication.SetAuthCookie(user.First().tblUserRole.RoleName, model.RememberMe); | |
Session["logged"] = user.First().Username; | |
string roleName = user.First().tblUserRole.RoleName; | |
Roles.AddUserToRole(model.UserName, roleName); | |
return RedirectToAction("Index", "Home"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is just a modification of the original code posted. It's modified to clean up the Cyclomatic Complexity... just a little bit. Deeply nested
if
statements kinda get under my skin.I hope this is helpful.