Beispiel #1
0
 public async Task <IActionResult> Edit(int id, [Bind("UId,FirstName,LastName,Email,UserName,Password,ConfirmPassword,UPriv")] UserAcccount userAcccount)
 {
     if (id != userAcccount.UId)
     {
         return(NotFound());
     }
     using (ApplicationDbContextcs db = new ApplicationDbContextcs())
     {
         if (ModelState.IsValid)
         {
             try
             {
                 db.Update(userAcccount);
                 await db.SaveChangesAsync();
             }
             catch (DbUpdateConcurrencyException)
             {
                 if (!UserAcccountExists(userAcccount.UId))
                 {
                     return(NotFound());
                 }
                 else
                 {
                     throw;
                 }
             }
             string url = @"../../App/Settings";
             return(Redirect(url));
         }
         return(View(userAcccount));
     }
 }
        public ActionResult Register(UserAcccount account)
        {
            Person        person = new Person();
            StringBuilder sbHash = new StringBuilder();

            person.user_id  = account.user_id;
            person.email    = account.email;
            person.fullName = account.fullName;
            person.active   = true;

            using (SHA256 hash = SHA256Managed.Create())
            {
                Encoding enc    = Encoding.UTF8;
                Byte[]   result = hash.ComputeHash(enc.GetBytes(account.password));
                foreach (Byte b in result)
                {
                    sbHash.Append(b.ToString("x2"));
                }
            }

            person.password = sbHash.ToString();
            if (ModelState.IsValid)
            {
                if (dal.RegisterUser(person))
                {
                    ModelState.Clear();
                    ViewBag.Message = $"{account.fullName } Created Succesfully!";
                }
            }

            return(View());
        }
        public ActionResult Login(UserAcccount user)
        {
            StringBuilder sbHash = new StringBuilder();

            using (SHA256 hash = SHA256Managed.Create())
            {
                Encoding enc    = Encoding.UTF8;
                Byte[]   result = hash.ComputeHash(enc.GetBytes(user.password));
                foreach (Byte b in result)
                {
                    sbHash.Append(b.ToString("x2"));
                }
            }

            user.password = sbHash.ToString();
            var usr = dal.Authenticateuser(user);

            if (usr != null)
            {
                Session["UserId"]   = usr.user_id.ToString();
                Session["UserName"] = usr.fullName.ToString();
                return(RedirectToAction("LoggedIn"));
            }
            else
            {
                ModelState.AddModelError("", "UserName/Password are incorrect");
            }
            //using (FSDEntities dbContext = new FSDEntities())
            //{
            //    try
            //    {
            //        var usr = dbContext.People.Single(x => x.user_id == user.user_id && x.password == user.password);
            //        if (usr != null)
            //        {
            //            Session["UserId"] = usr.user_id.ToString();
            //            Session["UserName"] = usr.fullName.ToString();
            //            return RedirectToAction("LoggedIn");
            //        }
            //        else
            //        {
            //            ModelState.AddModelError("", "UserName/Password are incorrect");
            //        }
            //    }

            //    catch {
            //        ModelState.AddModelError("", "UserName/Password are incorrect");
            //    }
            //}

            return(View());
        }
Beispiel #4
0
        public async Task <IActionResult> Create([Bind("UId,FirstName,LastName,Email,UserName,Password,ConfirmPassword,UPriv")] UserAcccount userAcccount)
        {
            using (ApplicationDbContextcs db = new ApplicationDbContextcs())
            {
                if (ModelState.IsValid)
                {
                    db.Add(userAcccount);
                    await db.SaveChangesAsync();

                    string url = @"../../App/Settings";
                    return(Redirect(url));
                }
                return(View(userAcccount));
            }
        }
Beispiel #5
0
        public Person Authenticateuser(UserAcccount user)
        {
            Person p = new Person();

            using (FSDEntities dbContext = new FSDEntities())
            {
                try
                {
                    p = dbContext.People.Single(x => x.user_id == user.user_id && x.password == user.password);
                }
                catch
                {
                    p = null;
                }
            }
            return(p);
        }
Beispiel #6
0
 public IActionResult Register(UserAcccount account)
 {
     try
     {
         addViewBags();
     }
     catch (Exception e) { Console.WriteLine(e.StackTrace); }
     if (ModelState.IsValid)
     {
         using (ApplicationDbContextcs db = new ApplicationDbContextcs())
         {
             db.userAccount.Add(account);
             db.SaveChanges();
         }
         ModelState.Clear();
         ViewBag.Message = account.FirstName + " " + account.LastName + " Successfully registered.";
     }
     return(View());
 }
Beispiel #7
0
 public IActionResult Login(UserAcccount user)
 {
     using (ApplicationDbContextcs db = new ApplicationDbContextcs())
     {
         try
         {
             var usr = db.userAccount.Single(u => u.UserName == user.UserName && u.Password == user.Password);
             HttpContext.Session.SetInt32("UserID", usr.UId);
             HttpContext.Session.SetString("UserName", usr.UserName.ToString());
             HttpContext.Session.SetInt32("UserPriv", usr.UPriv);
             return(Redirect("Index"));
         }
         catch (Exception e)
         {
             ModelState.AddModelError("", "UserName or Password is wrong!");
         }
     }
     return(View());
 }