public ActionResult Register(Models.Registration user) { try { if (ModelState.IsValid) { using (var db = new LoginInMVC4WithEF.Models.UserEntities2()) { var crypto = new SimpleCrypto.PBKDF2(); var encrypPass = crypto.Compute(user.Password); var newUser = db.Registrations.Create(); newUser.Email = user.Email; newUser.Password = encrypPass; newUser.PasswordSalt = crypto.Salt; newUser.FirstName = user.FirstName; newUser.LastName = user.LastName; newUser.UserType = "User"; newUser.CreatedDate = DateTime.Now; newUser.IsActive = true; newUser.IPAddress = "642 White Hague Avenue"; db.Registrations.Add(newUser); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Data is not correct"); } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } return(View()); }
private bool IsValid(string email, string password) { var crypto = new SimpleCrypto.PBKDF2(); bool IsValid = false; using (var db = new LoginInMVC4WithEF.Models.UserEntities2()) { var user = db.Registrations.FirstOrDefault(u => u.Email == email); if (user != null) { if (user.Password == crypto.Compute(password, user.PasswordSalt)) { IsValid = true; } } } return(IsValid); }