public JsonResult Registration(string email, string password)//Models.UserModel user) { UserModel user = new UserModel(email, password); if (ModelState.IsValid) { using (var db = new UnitBookingDataContext()) { var crypto = new SimpleCrypto.PBKDF2(); var encrpPass = crypto.Compute(user.Password); User u = new User() { Email = user.Email, Password = encrpPass, PasswordSalt = crypto.Salt }; try { //Retrieve the first user account with an email mathcing the email provided var dbUserAccount = db.Users.FirstOrDefault(uAcc => uAcc.Email == email); if (dbUserAccount == null) { db.Users.InsertOnSubmit(u); db.SubmitChanges(); } else { return(Json(new { result = "error", message = "Sorry, a user account already exists with that email address" })); } } catch (Exception e) { //log error } } } else { ModelState.AddModelError("", "Login data is incorrect!"); } //return View(); return(Json(new { result = "Redirect", url = Url.Action("Index", "Home") })); }
private bool IsValid(string email, string password) { try { var crypto = new SimpleCrypto.PBKDF2(); bool IsValid = false; using (var db = new UnitBookingDataContext()) { //Retrieve the first user with the email provided var user = db.Users.FirstOrDefault(u => u.Email == email); //If the user exists check if the password provided matches the store password after hashing if (user != null) { // Store the user temporarily in the context for this request. System.Web.HttpContext.Current.Items.Add("User", user); if (user.Password == crypto.Compute(password, user.PasswordSalt)) { //If the credentials provided are correct return true indicating the login was valid IsValid = true; } } else { //If the credentials were invalid return false indicating the credentials were invalid IsValid = false; } } return(IsValid); } catch (Exception e) { return(false); //Log error } }
private bool IsValid(string email, string password) { try { var crypto = new SimpleCrypto.PBKDF2(); bool IsValid = false; using (var db = new UnitBookingDataContext()) { //Retrieve the first user with the email provided var user = db.Users.FirstOrDefault(u => u.Email == email); //If the user exists check if the password provided matches the store password after hashing if (user != null) { // Store the user temporarily in the context for this request. System.Web.HttpContext.Current.Items.Add("User", user); if (user.Password == crypto.Compute(password, user.PasswordSalt)) { //If the credentials provided are correct return true indicating the login was valid IsValid = true; } } else { //If the credentials were invalid return false indicating the credentials were invalid IsValid = false; } } return IsValid; } catch (Exception e) { return false; //Log error } }
public JsonResult Registration(string email, string password) { UserModel user = new UserModel(email, password); if (ModelState.IsValid) { using (var db = new UnitBookingDataContext()) { var crypto = new SimpleCrypto.PBKDF2(); var encrpPass = crypto.Compute(user.Password); User u = new User() { Email = user.Email, Password = encrpPass, PasswordSalt = crypto.Salt }; try { //Retrieve the first user account with an email mathcing the email provided var dbUserAccount = db.Users.FirstOrDefault(uAcc => uAcc.Email == email); if (dbUserAccount == null) { db.Users.InsertOnSubmit(u); db.SubmitChanges(); } else { return Json(new { result = "error", message = "Sorry, a user account already exists with that email address" }); } } catch (Exception e) { //log error } } } else { ModelState.AddModelError("", "Login data is incorrect!"); } //return View(); return Json(new { result = "Redirect", url = Url.Action("Index", "Home") }); }