예제 #1
0
        private void AuthenticateUser(string username, string password)
        {
            BAL.Login         bAL        = new BAL.Login();
            Models.LoginModel loginModel = new Models.LoginModel();
            loginModel.Username = username;
            loginModel.Password = password;
            DataTable dt = bAL.checkUser(loginModel);

            foreach (DataRow row in dt.Rows)
            {
                int RetryAttempts = Convert.ToInt32(row["RetryAttempts"]);
                if (Convert.ToBoolean(row["AccountLocked"]))
                {
                    lblMessage.Text = "Account locked. Please contact administrator";
                }
                else if (RetryAttempts > 0)
                {
                    int AttemptsLeft = (4 - RetryAttempts);
                    lblMessage.Text = "Invalid user name and/or password. " +
                                      AttemptsLeft.ToString() + "attempt(s) left";
                }
                else if (Convert.ToBoolean(row["Authenticated"]))
                {
                    string UserId = (row["UserId"].ToString());
                    FormsAuthentication.RedirectFromLoginPage(UserId, cbRememberMe.Checked);
                }
            }
        }
예제 #2
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var login = model.Login;
                var passwordHash = _cryptoProvider.GetHash(model.Password, Salt);

                var userEntity =
                    _dContext.Users.FirstOrDefault(x => x.Login == login && x.PasswordHash == passwordHash);

                if (userEntity != null)
                {
                    var authTicket = new FormsAuthenticationTicket(
                        1,
                        login,
                        DateTime.Now,
                        DateTime.Now.AddMinutes(20),
                        true,
                        userEntity.UserRole.ToString()
                        );
                    string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                    var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                    System.Web.HttpContext.Current.Response.Cookies.Add(authCookie);
                    return RedirectToAction("Index", "Admin");
                }
                else
                {
                    ModelState.AddModelError("", "The user login or password provided is incorrect.");
                }
            }
            return View(model);
        }
예제 #3
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
예제 #4
0
        public ActionResult LogOn(LoginModel login, string returnUrl)
        {
            if (ModelState.IsValid && login != null)
            {
                try
                {
                    string password = Encryption.Rijndael.Encrypt(login.Password);

                    var user = this.db
                                   .Usuarios
                                   .Include("Roles")
                                   .FirstOrDefault(
                                        u => u.USUUsuario == login.User && u.USUClave == password && u.USUActivo
                                    );

                    if (user == null)
                        ModelState.AddModelError("", "El nombre de usuario o contraseña ingresados no son validos.");
                    else 
                    {
                        FormsAuthentication.SetAuthCookie(user.USUID.ToString(), login.RememberMe);
                        CurrentHttpContext.User = user.CastToDTOCurrentUser();
                        return RedirectToLocal(returnUrl); //return RedirectToAction("Index", "Home");
                    }
                }
                catch (Exception exc){
                    Utils.AddException(exc, level: LogExceptionLevel.High);
                    ModelState.AddModelError("", "No se ha logrado realizar la autenticación, favor intente mas tarde.");
                }
            }
            else
                ModelState.AddModelError("", "Los datos ingresados no son validos.");

            return View();
        }
예제 #5
0
 public LoginModel convertToUI(User user)
 {
     var logModel = new LoginModel();
     logModel.Email = user.Email;
     logModel.Password = user.Password;
     logModel.Roles = user.Roles;
     return logModel;
 }
예제 #6
0
 public ActionResult Login(LoginModel model)
 {
     if (currentUserService.ConfirmActivated(model.Email)!= true)
     {
         return View("Login");
     }
     SessionPersister.Email = model.Email;
     return RedirectToAction("Information", "User");
 }
예제 #7
0
        public void LoginPostModel_Invalid_Test()
        {
            var model = new LoginModel();
            adminController.ModelState.AddModelError("Username", "UserName is required");

            var actual = adminController.Login(model, "/");

            Assert.IsInstanceOf<ViewResult>(actual);
        }
예제 #8
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && authorizeProvider.Login(model.UserName, model.Password))
            {
                return RedirectToUrl(returnUrl);
            }

            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }
예제 #9
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
              {
            return RedirectToLocal(returnUrl);
              }

              // If we got this far, something failed, redisplay form
              ModelState.AddModelError("", "The user name or password provided is incorrect.");
              return View(model);
        }
예제 #10
0
        public AdminServices()
        {
            loginModel = new LoginModel();
            loginBal = new LoginBAL();
            tLoginData = new TLoginData();

            _serializer = new JavaScriptSerializer();

            userMangementModel = new UserManagementModel();
            userManagementBAL = new UserManagementBAL();
            tuserMangementData = new TUserManagementData();


        }
예제 #11
0
 public ActionResult Index(Models.LoginModel model)
 {
     //var result = new AccountModel().Login(model.UserName, model.Password);
     if (Membership.ValidateUser(model.UserName, model.Password) && ModelState.IsValid)
     {
         //SessionHelper.SetSession(new UserSession() { UserName = model.UserName });
         FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
         return(RedirectToAction("Index", "Home"));
     }
     else
     {
         ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu chưa đúng");
     }
     return(View(model));
 }
예제 #12
0
        public void LoginPostUser_Invalid_Test()
        {
            var model = new LoginModel
            {
                UserName = "******",
                Password = "******"
            };
            authorizeProvider.Stub(s => s.Login(model.UserName, model.Password)).Return(false);

            var actual = adminController.Login(model, "/");

            Assert.IsInstanceOf<ViewResult>(actual);
            var modelStateErrors = adminController.ModelState[""].Errors;
            Assert.IsTrue(modelStateErrors.Count > 0);
            Assert.AreEqual("The user name or password provided is incorrect.", modelStateErrors[0].ErrorMessage);
        }
예제 #13
0
        public TLoginData validateUser(string data)
        {
            try
            {
                loginModel = _serializer.Deserialize<LoginModel>(data);
                tLoginData = loginBal.validateUser(loginModel);

                return tLoginData;

            }
            catch (Exception exp)
            {
                tLoginData.ErrorCode = ErrorCodes.SERVICE_ERROR;
                tLoginData.ErrorMessage = "validateUser: " + exp.InnerException.ToString();
                return tLoginData;
            }
        }
예제 #14
0
        public ActionResult Index(Models.LoginModel mode)
        {
            if (ModelState.IsValid)
            {
                var dao    = new DBModel.DAO.UserDao();
                var result = dao.Login(mode.UserName, SecurityHelper.MD5Hash(mode.UserName + mode.Password));
                if (result == 1)
                {
                    var       us    = dao.GetUserByUserName(mode.UserName);
                    UserLogin uslog = new UserLogin();
                    uslog.UserID    = us.LoginID;
                    uslog.UserName  = us.UserName;
                    uslog.FullName  = us.FullName;
                    uslog.Image     = us.Image;
                    uslog.LastLogIn = us.LastLogIn;
                    Session[SystemConsts.USER_SESSION] = uslog;
                    dao.LastLogin(us.LoginID, Hepper.GetDateServer());
                    //if (mode.Remember)
                    //{

                    //    HttpCookie aCookie = new HttpCookie("login");
                    //    aCookie.Values["UserName"] = mode.UserName;
                    //    aCookie.Values["Password"] = mode.Password;
                    //    aCookie.Expires = DateTime.Now.AddDays(365);
                    //    aCookie.Secure = true;
                    //    ControllerContext.HttpContext.Response.Cookies.Add(aCookie);

                    //}
                    return(RedirectToAction("Index", "Home"));
                }
                else if (result == 0)
                {
                    ModelState.AddModelError("", "Tài khoản không tồn tại.");
                }
                else if (result == -1)
                {
                    ModelState.AddModelError("", "Tài khoản đã bị khóa.");
                }
                else if (result == -2)
                {
                    ModelState.AddModelError("", "Mật khẩu không đúng");
                }
            }
            return(View());
        }
예제 #15
0
        public ActionResult Logar(LoginModel model)
        {
            if ("tiago".Equals(model.Usuario, StringComparison.InvariantCultureIgnoreCase) &&
                        model.Senha.Equals("soczek"))
            {
                FormsAuthentication.SetAuthCookie(model.Usuario, true);

                if (!string.IsNullOrWhiteSpace(model.ReturnUrl))
                {
                    return Redirect(model.ReturnUrl);
                }

                return Redirect("~/");
            }

            model.Erro = true;
            model.Mensagem = "Usuario ou senha incorretos";

            return View("Index", model);
        }
예제 #16
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false);

                    if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }

                    return RedirectToAction("Manage");
                }

                ModelState.AddModelError("", "The user name or password provided is incorrect.");
            }

            return View();
        }
예제 #17
0
 public async Task<object> SignIn(LoginModel model)
 {
     var userRole = await BLL.T_Customer_BLL.CheckUserName(model.UserName, model.Password);
     if (userRole != null)
     {
         HttpContext.Current.Session["User"] = userRole;
         FormsAuthentication.SetAuthCookie(userRole.UserName, false);
         return Ok(new
         {
             statusCode = HttpStatusCode.OK,
             result = "登录成功"
         });
     }
     else
     {
         return Ok(new
         {
             statusCode = HttpStatusCode.Forbidden,
             result = "错误的用户名或密码."
         });
     }
 }
예제 #18
0
        public TLoginData validateUser(IModel model)
        {
            try
            {
                modelEntity = (LoginModel)model;

                var record =
                    _dataContext.UserMangements.Where(x => x.LoginName == modelEntity.UserId && x.Password == modelEntity.Password).ToList();

                if (record.Count > 0)
                {
                    tLoginData.SuccessCode = ErrorCodes.VALID_USER;
                    modelEntity.UserId = record[0].LoginName;
                    modelEntity.Role = record[0].Role;
                    tLoginData.tLoginData = modelEntity;

                    return tLoginData;


                }
                else
                {
                    tLoginData.ErrorCode = ErrorCodes.INVALID_USER;
                    tLoginData.ErrorMessage = ErrorMessages.INVALID_USER_MSG;
                    return tLoginData;
                }
            }

            catch (Exception e)
            {
                tLoginData.ErrorCode = ErrorCodes.DATA_ACCESS_ERROR;
                tLoginData.ErrorMessage = "validateUser: " + e.InnerException.ToString();
                return tLoginData;
            }

        }
예제 #19
0
 public ActionResult Index(LoginModel model)
 {
     return View(model);
 }
예제 #20
0
        public void LoginPostUser_Valid_Test()
        {
            var model = new LoginModel
            {
                UserName = "******",
                Password = "******"
            };
            authorizeProvider.Stub(s => s.Login(model.UserName, model.Password)).Return(true);

            var actual = adminController.Login(model, "/");

            Assert.IsInstanceOf<RedirectResult>(actual);
            Assert.AreEqual("/", ((RedirectResult)actual).Url);
        }
예제 #21
0
 public ActionResult Login(string returnUrl)
 {
     var loginModel = new LoginModel();
     ViewBag.ReturnUrl = returnUrl;
     return View(loginModel);
 }
예제 #22
0
 public CustomPrincipal(LoginModel login)
 {
     this.Login = login;
     this.Identity = new GenericIdentity(login.Email);
 }
예제 #23
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = ExecuteCommand(new LoginUserCommand(model.Email, model.Password));
                if (user != null && !user.IsLocked)
                {
                    var userInfo = Mapper.Map<UserInfo>(user);
                    Session[SessionKeys.User] = userInfo;

                    _formsAuthenticationService.SignIn(model.Email, model.RememberMe);

                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else if (user != null && user.IsLocked)
                {
                    ModelState.AddModelError(string.Empty, "Your account is locked.");
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
예제 #24
0
 public LoginBAL()
 {
     loginDal = new LoginDAL();
     loginModel = new LoginModel();
     tloginData = new TLoginData();
 }