Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two table name Register and Login,
when user logs in the, user id and its status=1 will be store in Logins table and when user logs out status will become 0.

my problem is how should i check at login time that user is already logged in or not,
any if conditions to check, below is my code


public ActionResult GetLogin(Register d, Login r)
       {
           using (simpleEntities _LoginEntities = new simpleEntities())
           {
               var user = _LoginEntities.Registers.Where(u => u.Email.Equals(d.Email) && u.Password.Equals(d.Password)).FirstOrDefault();
               string message = "User already logged in";
                   //List<Login> abc = new List<Login>();
                   //bool aa = false;
                   //var user1 = _LoginEntities.Logins.Where(u => u.LogID.Equals(user.ID) && u.Status==(false)).FirstOrDefault();
                       if (user != null)
                       {

                                 //SELECT    *
                                 //  FROM    Notification n
                                 //  LEFT OUTER JOIN Acknowledgment a ON a.parent_id = n.id
                                 //      WHERE     (a.parent_id IS NULL OR a.status = @somevalue)
                           List<Login> ddd = new List<Login>();
                           ddd = (from a in db.Logins where a.LogID == user.ID where (a.Status == (false)) select a).ToList();
                           if (ddd!=null)
                           {
                               Session["ID"] = user.ID.ToString();
                               Session["Email"] = user.Email.ToString();
                               Session["Username"] = user.Fname.ToString() + "" + user.Lname.ToString();
                               return RedirectToAction("UserDashBoard");
                           }
                           else
                           {
                               return Json(message, JsonRequestBehavior.AllowGet);
                           }
                       }
                       return View();
                   }
                }


What I have tried:

i tried with if conditions, first it checks in register table then in login table but no success, plz help me out with this
Posted
Updated 4-Jan-18 3:05am
Comments
Dheerajs975 4-Jan-18 5:01am    
i just want to make my site more secure... and its possible,
like when user enters their credential for login first system will check in register table that credential are correct or not. if yes then it will go into login table and check that the entered credential login status is true or false, if its true then it will not allow to login and if its false then user will be redirect to Dashboard or Home page
F-ES Sitecore 4-Jan-18 5:23am    
Why does preventing multiple logins make your site more secure? If I choose to log into my webmail in two tabs why is that less secure than having only logged in once?
Dheerajs975 4-Jan-18 5:37am    
what can i do if client ask me for prevent multiple login..?
author wants to prevent multiple logins with same username and password
F-ES Sitecore 4-Jan-18 5:59am    
You tell them it's not possible and you explain there is no value in it. Part of being a developer is managing client expectations.

1 solution

As mentioned in the comments, it is a bad idea to do it. However, all you have to do is write code to check the flag in the db to see if they are logged in. You'll want to add some sort of timeout option or reset option so that if the user does close the browser without logging out they'll still have a way to get back in.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900