Exemple #1
0
 public bool IsAuthenticated(string login, string token)
 {
     using (var context = new LaborExchangeEntities())
     {
         var userArray = (from l in context.Logins where l.Username == login select l).ToArray();
         if (userArray.Length != 1)
         {
             return(false);
         }
         string hash = userArray[0].Pass;
         string htnk = MakeToken(login, hash);
         return(token == htnk);
     }
 }
Exemple #2
0
        public bool CheckCreds(string login, string password)
        {
            string hash = MakeHash(login, password);

            using (var context = new LaborExchangeEntities())
            {
                var userArray = (from l in context.Logins where l.Username == login select l).ToArray();
                if (userArray.Length != 1)
                {
                    return(false);
                }
                return(hash == userArray[0].Pass);
            }
        }
Exemple #3
0
        public bool AddUser(string login, string password, string type, List <string> args)
        {
            string hash = MakeHash(login, password);

            using (var context = new LaborExchangeEntities())
            {
                if (Enumerable.Any(context.Logins, contextLogin => contextLogin.Username == login))
                {
                    return(false);
                }

                var l = new Logins
                {
                    Username = login,
                    Pass     = hash,
                    UserType = type
                };
                context.Logins.Add(l);
                switch (type)
                {
                case "Company":
                    if (!AddCompany(l, args))
                    {
                        return(false);
                    }
                    break;

                case "Employee":
                    if (!AddEmployee(l, args))
                    {
                        return(false);
                    }
                    break;
                }
                context.SaveChanges();
                return(true);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Authenticated())
            {
                Response.Redirect("Default.aspx");
            }


            List <Ent> ent = new List <Ent>();

            using (var context = new LaborExchangeEntities())
            {
                ent = (from s
                       in context.CompanyType
                       select new Ent
                {
                    Type = s.Type,
                    ID = s.ID
                }).ToList();

                dgUsers.DataSource = (from c in context.Logins
                                      select new Ent2
                {
                    Username = c.Username,
                    ID = c.ID,
                    UserType = c.UserType,
                    Pass = c.Pass
                }).ToList();
                dgUsers.DataBind();
                rptTypes.DataSource = ent;
                rptTypes.DataBind();
            }


            //lblHello.Text = $"Hello, {SQLiteLogic.SQLiteController.Instance.GetUserShowname(Request.Cookies["login"].Value)}";
            btnLogout.Click += BtnLogout_Click;
        }