Ejemplo n.º 1
0
        private bool IsValid(string email, string password)
        {
            var  crypto  = new SimpleCrypto.PBKDF2();
            bool IsValid = false;

            using (var db = new MvcApplication1.Models.RegistrationEntities())
            {
                var user = db.Employees.FirstOrDefault(u => u.Email == email);
                if (user != null)
                {
                    if (user.Password == crypto.Compute(password, user.PasswordSalt))
                    {
                        IsValid = true;
                    }
                }
            }
            return(IsValid);
        }
Ejemplo n.º 2
0
 public ActionResult Register(Models.Employee employee)
 {
     try
     {
         if (ModelState.IsValid)
         {
             using (var db = new MvcApplication1.Models.RegistrationEntities())
             {
                 setId();
                 var crypto    = new SimpleCrypto.PBKDF2();
                 var encryPass = crypto.Compute(employee.Password);
                 var newUser   = db.Employees.Create();
                 newUser.EmployeeID   = this.id;
                 newUser.FirstName    = employee.FirstName;
                 newUser.LastName     = employee.LastName;
                 newUser.Email        = employee.Email;
                 newUser.UserType     = employee.UserType;
                 newUser.Password     = encryPass;
                 newUser.PasswordSalt = crypto.Salt;
                 newUser.CreatedDate  = DateTime.Now;
                 newUser.IPAddress    = "Not Available";
                 db.Employees.Add(newUser);
                 db.SaveChanges();
                 return(RedirectToAction("Login", "Registration"));
             }
         }
         else
         {
             ModelState.AddModelError("", "Data is not correct");
         }
     }
     catch (DbUpdateException e)
     {
     }
     catch (DbEntityValidationException e)
     {
     }
     return(View(employee));
 }