Пример #1
0
        public ActionResult Create([Bind(Include = "Id,UserName,Password,RegisterId")] LoginTbl loginTbl, string userName, string password, RegisterTbl registerTbl, int?id)
        {
            if (ModelState.IsValid)
            {
                var query = (from u in db.RegisterTbls
                             where u.UserName == userName && u.Password == password
                             select u).FirstOrDefault();



                if (query != null)
                {
                    loginTbl.RegisterId = query.Id;
                    db.LoginTbls.Add(loginTbl);

                    db.SaveChanges();

                    Session["username"] = loginTbl.UserName;

                    return(RedirectToAction("Index"));
                }
                else

                {
                    return(RedirectToAction("Create"));
                }
            }

            ViewBag.RegisterId = new SelectList(db.RegisterTbls, "Id", "Email", loginTbl.RegisterId);
            return(View(loginTbl));
        }
Пример #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            LoginTbl loginTbl = db.LoginTbls.Find(id);

            db.LoginTbls.Remove(loginTbl);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #3
0
 public ActionResult Edit([Bind(Include = "Id,UserName,Password,RegisterId")] LoginTbl loginTbl)
 {
     if (ModelState.IsValid)
     {
         db.Entry(loginTbl).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.RegisterId = new SelectList(db.RegisterTbls, "Id", "Email", loginTbl.RegisterId);
     return(View(loginTbl));
 }
Пример #4
0
        public async Task <IActionResult> Index(LoginTbl login)
        {
            if (login.Username == "" || login.Pass == "")
            {
                return(NotFound());
            }
            else
            {
                byte[] salt = new byte[128 / 8];
                //using (var rng = RandomNumberGenerator.Create())
                //{
                //    rng.GetBytes(salt);
                //}
                //Console.WriteLine($"Salt: {Convert.ToBase64String(salt)}");

                // derive a 256-bit subkey (use HMACSHA1 with 10,000 iterations)
                string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
                                                           password: login.Pass,
                                                           salt: salt,
                                                           prf: KeyDerivationPrf.HMACSHA1,
                                                           iterationCount: 10000,
                                                           numBytesRequested: 256 / 8));
                var a = hashed;

                var search = _db.LoginTbl.FirstOrDefault(m => m.Username == login.Username && m.Pass == a);

                if (search == null)
                {
                    //ModelState.AddModelError(string.Empty, "Employee Doesn't Exist");
                    TempData["MsgNoData"] = "Wrong Username Or Password";
                    return(View());
                }
                else
                {
                    //var name = _db.LoginTbl.FirstOrDefault(m => m.Username == login.Username && m.Pass == login.Pass);
                    //var role = _context.UserLogin.Where(x => x.UserId == userFromRepo.UserId).First().Role;
                    var claims = new List <Claim>();
                    //claims.Add(new Claim(ClaimTypes.NameIdentifier, userFromRepo.Id.ToString()));
                    claims.Add(new Claim(ClaimTypes.Name, search.name));
                    claims.Add(new Claim(ClaimTypes.Role, search.type));
                    //claims.Add(new Claim(ClaimTypes.Role, role.ToString()));
                    var identity        = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                    var claimsPrincipal = new ClaimsPrincipal(identity);
                    Thread.CurrentPrincipal = claimsPrincipal;
                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity));

                    HttpContext.Session.SetString("Username", search.Username);

                    //return View("Index");
                    return(RedirectToAction("Index", "Home"));
                }
            }
        }
Пример #5
0
        // GET: Login/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            LoginTbl loginTbl = db.LoginTbls.Find(id);

            if (loginTbl == null)
            {
                return(HttpNotFound());
            }
            return(View(loginTbl));
        }
Пример #6
0
        // GET: Login/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            LoginTbl loginTbl = db.LoginTbls.Find(id);

            if (loginTbl == null)
            {
                return(HttpNotFound());
            }
            ViewBag.RegisterId = new SelectList(db.RegisterTbls, "Id", "Email", loginTbl.RegisterId);
            return(View(loginTbl));
        }
        public ActionResult Login(LoginTbl obj)
        {
            if (ModelState.IsValid)
            {
                if (project.LoginTbls.Where(x => x.Username == obj.Username && x.Password == obj.Password).FirstOrDefault() == null)
                {
                    ViewBag.data = "You are not Registered!";
                }
                else
                {
                    ViewBag.data = "Login is Successfull.";
                    return(RedirectToAction("TransferFunds", "Login"));
                }
            }


            return(View());
        }
        public ActionResult TransferFunds(LoginTbl obj, string btn)
        {
            if (btn == "Transfer")
            {
                var data = project.LoginTbls.Where(x => x.AccountNo == obj.AccountNo).FirstOrDefault();
                if (obj.Amount != null)
                {
                    data.Amount -= obj.Amount;
                    int mess = project.SaveChanges();
                    if (mess == 1)
                    {
                        ViewBag.data = "Transfer is Done!";
                    }
                    else
                    {
                        ViewBag.data = "Transfer is not Successfull.";
                    }
                }
                else
                {
                    ViewBag.data = "Insufficient Balance.";
                }
            }


            if (btn == "View Balance")
            {
                var data = project.LoginTbls.Where(x => x.AccountNo == obj.AccountNo).FirstOrDefault();
                ViewBag.show = "The Available balance in your account is :  " + data.Amount;
            }
            //else
            //{
            //    ViewBag.show = "Wrong Details.";
            //}

            return(View());
        }
Пример #9
0
        public IActionResult signup(String aa, String bb, String cc, String dd, String ee, LoginTbl login)
        {
            byte[] salt = new byte[128 / 8];
            //using (var rng = RandomNumberGenerator.Create())
            //{
            //    rng.GetBytes(salt);
            //}
            //Console.WriteLine($"Salt: {Convert.ToBase64String(salt)}");

            // derive a 256-bit subkey (use HMACSHA1 with 10,000 iterations)
            string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
                                                       password: dd,
                                                       salt: salt,
                                                       prf: KeyDerivationPrf.HMACSHA1,
                                                       iterationCount: 10000,
                                                       numBytesRequested: 256 / 8));
            var a = hashed;

            login.name     = aa;
            login.Email    = bb;
            login.Username = cc;
            login.Pass     = a;
            login.type     = ee;

            if (ModelState.IsValid)
            {
                _db.Add(login);
                _db.SaveChangesAsync();
                //return RedirectToAction("Index", "Home");
                return(Json(new { success = true }));
            }
            return(View());
        }
Пример #10
0
        public ActionResult Login([Bind(Include = "Id,UserName,Password,RegisterId")] LoginTbl loginTbl, string userName, string password, RegisterTbl registerTbl, int?id, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var query = (from u in db.RegisterTbls
                             where u.UserName == userName && u.Password == password
                             select u).FirstOrDefault();



                if (query != null)
                {
                    loginTbl.RegisterId = query.Id;
                    db.LoginTbls.Add(loginTbl);

                    db.SaveChanges();

                    //   await SignInAsync(registerTbl, model.RememberMe);

                    //   return RedirectToLocal(returnUrl);
                }
                else

                {
                    return(RedirectToAction("Login"));
                }
                var ident = new ClaimsIdentity(
                    new[] {
                    // adding following 2 claim just for supporting default antiforgery provider
                    new Claim(ClaimTypes.NameIdentifier, userName),
                    new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity", "http://www.w3.org/2001/XMLSchema#string"),

                    new Claim(ClaimTypes.Name, userName),

                    // optionally you could add roles if any
                    new Claim(ClaimTypes.Role, "RoleName"),
                    new Claim(ClaimTypes.Role, "AnotherRole"),
                },
                    DefaultAuthenticationTypes.ApplicationCookie);

                HttpContext.GetOwinContext().Authentication.SignIn(
                    new AuthenticationProperties {
                    IsPersistent = false
                }, ident);
                return(RedirectToLocal(returnUrl));
                //  return RedirectToAction("MyAction"); // auth succeed
            }
            ViewBag.RegisterId = new SelectList(db.RegisterTbls, "Id", "Email", loginTbl.RegisterId);
            return(View(loginTbl));

            /*
             * if (ModelState.IsValid)
             * {
             *  var user = await UserManager.FindAsync(model.UserName, model.Password);
             *  if (user != null)
             *  {
             *
             *      await SignInAsync(user, model.RememberMe);
             *      return RedirectToLocal(returnUrl);
             *  }
             *  else
             *  {
             *      ModelState.AddModelError("", "Invalid username or password.");
             *  }
             * }
             *
             * // If we got this far, something failed, redisplay form
             * return View(model);
             */
        }