public ActionResult Register(user user) { if (!checkUser(user.Email)) { try { if (ModelState.IsValid) { string EncodedResponse = Request.Form["g-Recaptcha-Response"]; bool IsCaptchaValid = (ReCaptchaClass.Validate(EncodedResponse) == "True" ? true:false); if (IsCaptchaValid) { using (var db = new ecm.Models.ecmEntities2()) { var crypto = new SimpleCrypto.PBKDF2(); var encrypPass = crypto.Compute(user.Password); var newUser = db.users.Create(); newUser.Email = user.Email; newUser.Password = encrypPass; newUser.PasswordSalt = crypto.Salt; newUser.FirstName = user.FirstName; newUser.LastName = user.LastName; newUser.UserType = user.UserType; db.users.Add(newUser); db.SaveChanges(); Session["username"] = user.Email; Session["userType"] = user.UserType; //FormsAuthentication.SetAuthCookie(user.Email, false); return(RedirectToAction("dashboard", "User")); } } else { TempData["recaptcha"] = "Please verify that you're not a robot"; } } } 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; } } else { TempData["error"] = "This email already exists!"; } return(View("Authentication")); }
private bool checkUser(string email) { bool IsUserExists = false; using (var db = new ecm.Models.ecmEntities2()) { var user = db.users.FirstOrDefault(u => u.Email == email); if (user != null) { IsUserExists = true; } } return(IsUserExists); }
private bool IsValid(string email, string password) { var crypto = new SimpleCrypto.PBKDF2(); bool IsValid = false; using (var db = new ecm.Models.ecmEntities2()) { var user = db.users.FirstOrDefault(u => u.Email == email); if (user != null) { if (user.Password == crypto.Compute(password, user.PasswordSalt)) { IsValid = true; flag = true; Uid = user.UserId; } } } return(IsValid); }