public ActionResult Authorize(MVCLogin.Models.User userModel)
 {
     using (LoginDataBaseEntities db = new LoginDataBaseEntities())
     {
         var userDetails = db.User.Where(x => x.UserName == userModel.UserName && x.Password == userModel.Password).FirstOrDefault();
         if (userDetails == null)
         {
             userModel.ErrorMeassage = "wrong username or pwd";
             return(View("Index", userModel));
         }
         else
         {
             Session["UserId"] = userDetails.UserID;
             return(RedirectToAction("Index", "Home"));
         }
     }
 }
Exemplo n.º 2
0
 public ActionResult Autherrize(MVCLogin.Models.User userModel)
 {
     using (LoginEntities2 db = new LoginEntities2())
     {
         var userDetails = db.Users.Where(x => x.UserName == userModel.UserName && x.Password == userModel.Password).FirstOrDefault();
         if (userDetails == null)
         {
             userModel.LoginErrorMessage = "Wrong username or password.";
             return(View("Index", userModel));
         }
         else
         {
             Session["userID"]   = userDetails.UserID;
             Session["userName"] = userDetails.UserName;
             return(RedirectToAction("Index", "Home"));
         }
     }
 }
Exemplo n.º 3
0
 public ActionResult Autherize(MVCLogin.Models.User userModel)
 {
     using (LoginDataBaseEntities db = new LoginDataBaseEntities())
     {
         var userDetails = db.User.Where(x => x.UserName == userModel.UserName && x.Password == userModel.Password).FirstOrDefault();
         if (userDetails == null)
         {
             userModel.LoginErrorMessage = "Usuario o contrasenia incorrecta";
             return(View("Index", userModel));
         }
         else
         {
             Session["userID"]   = userDetails.UserID;
             Session["userName"] = userDetails.UserName;
             return(RedirectToAction("Index", "Home"));
         }
     }
 }
Exemplo n.º 4
0
 public ActionResult Authorize(MVCLogin.Models.User userModel)
 {
     using (DatabaseEntities db = new DatabaseEntities())
     {
         var userDetails = db.Users.Where(x => x.UserName == userModel.UserName && x.Password == userModel.Password).FirstOrDefault();
         if (userDetails == null)
         {
             userModel.LoginErrorMessage = "Kullanıcı adı veya şifre yanlış";
             return(View("Index", userModel));
         }
         else
         {
             Session["UserID"]   = userDetails.UserID;
             Session["UserName"] = userDetails.UserName;
             return(RedirectToAction("Index", "Home"));
         }
     }
 }
 public ActionResult Autherize(MVCLogin.Models.User userModel)
 {
     using (Models.LoginDataBaseEntities db = new Models.LoginDataBaseEntities())
     {
         var userDetails = db.Users.Where(x => x.UserName == userModel.UserName).FirstOrDefault();
         if (userDetails == null)
         {
             userModel.LoginErrorMessage = "Wrong User Name Or Password";
             return(View("ForgetPassword", userModel));
         }
         else
         {
             Session["userID"]   = userDetails.UserID;
             Session["userName"] = userDetails.UserName;
             // return RedirectToAction("Index", "Home");
             return(View("Autherize", userModel));
         }
     }
 }
Exemplo n.º 6
0
        public ActionResult Autherize(MVCLogin.Models.User userModel)
        {
            using (LoginDataBaseEntities db = SingletonDB.Instance.GetDBConnection())
            {
                var userDetails = db.Users.Where(x => x.UserName == userModel.UserName && x.Password == userModel.Password).FirstOrDefault();
                //if is wrong user name or password
                if (userDetails == null)
                {
                    userModel.LoginErrorMessage = "Wrong user name or password.";
                    return(View("Index", userModel));
                }
                //if is right, save that id
                else
                {
                    List <User> data = new List <User>();
                    data.Add(new User()
                    {
                        UserName = userDetails.UserName,
                        Password = userDetails.Password
                    });

                    string json = JsonConvert.SerializeObject(data.ToArray());

                    string path = @"E:\MyTestJson.txt";
                    if (!System.IO.File.Exists(path))
                    {
                        using (StreamWriter file = System.IO.File.CreateText(path))
                        {
                            JsonSerializer serializer = new JsonSerializer();
                            //serialize object directly into file stream
                            serializer.Serialize(file, data);
                        }
                    }
                    Session["userID"]   = userDetails.UserID;
                    Session["userName"] = userDetails.UserName;
                    return(RedirectToAction("Index", "Home"));
                }
            }
        }
Exemplo n.º 7
0
        public ActionResult NewEntry(MVCLogin.Models.User userModel)
        {
            using (LoginDataBaseEntities db = new LoginDataBaseEntities())
            {
                var userDetails = db.Users.Where(x => x.UserName == userModel.UserName).FirstOrDefault();
                if (userDetails != null)
                {
                    userModel.LoginErrorMessage = "Username Already Taken!";
                    return(View("Create", userModel));
                }
                else
                {
                    User user = new User();
                    user.UserName = userModel.UserName;
                    user.Password = userModel.Password;

                    db.Users.Add(user);
                    db.SaveChanges();

                    int latestId = user.UserID;
                    return(RedirectToAction("Index"));
                }
            }
        }
        public ActionResult Autherize(MVCLogin.Models.User userModel)
        {
            HttpCookie cookie = new HttpCookie("User");

            if (userModel.Remember == true)
            {
                cookie["UserName"] = userModel.UserName;
                cookie["Password"] = userModel.Password;
                cookie.Expires     = DateTime.Now.AddYears(1);
                HttpContext.Response.Cookies.Add(cookie);
            }
            else
            {
                cookie.Expires = DateTime.Now.AddYears(-1);
                HttpContext.Response.Cookies.Add(cookie);
            }
            using (Models.LoginDataBaseEntities db = new Models.LoginDataBaseEntities())
            {
                if (Session["trial1"] != null && string.Equals(trialtemp, userModel.UserName))
                {
                    ViewBag.Report = "Your Login is temporary Blocked for 5 min";
                    return(View("Index", userModel));
                }
                else if (Session["trial2"] != null && string.Equals(trialtemp, userModel.UserName))
                {
                    ViewBag.Report = "Your Login is temporary Blocked for 15 min";
                    return(View("Index", userModel));
                }
                else
                {
                    var userDetails = db.Users.Where(x => x.UserName == userModel.UserName && x.Password == userModel.Password).FirstOrDefault();
                    if (userDetails == null)
                    {
                        if (trial == 0)
                        {
                            trialtemp = userModel.UserName;
                            trial     = trial + 1;
                        }
                        else if (string.Equals(trialtemp, userModel.UserName))
                        {
                            trial = trial + 1;
                            if (trial == 3)
                            {
                                Session["trial1"] = userModel.UserName;
                                Session.Timeout   = 1;
                            }
                            else if (trial == 6)
                            {
                                Session["trial2"] = userModel.UserName;
                                Session.Timeout   = 1;
                            }
                            else if (trial == 9)
                            {
                            }
                        }
                        else
                        {
                            trialtemp = userModel.UserName;
                            trial     = 1;
                        }
                        userModel.LoginErrorMessage = "Wrong User Name Or Password";
                        return(View("Index", userModel));
                    }
                    else
                    {
                        trial     = 0;
                        trialtemp = null;

                        Session["userID"]   = userDetails.UserID;
                        Session["userName"] = userDetails.UserName;
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }
        }