Exemplo n.º 1
0
 public User UpdateNavToLisk(string id)
 {
     using (DBentities DB = new DBentities())
     {
         User returnedUser = (from u in DB.Users
                              where u.ResetPasswordCode.ToString() == id
                              select u).FirstOrDefault();
         return(returnedUser);
     }
 }
Exemplo n.º 2
0
 public User UsernameExists(string username)
 {
     using (DBentities db = new DBentities())
     {
         User returnedUser = (from u in db.Users
                              where u.UserName == username
                              select u).FirstOrDefault();
         //User v = db.Users.Where(a => a.Email == emailID).FirstOrDefault();
         return(returnedUser);
     }
 }
Exemplo n.º 3
0
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (DBentities db = new DBentities())
            {
                db.Configuration.ValidateOnSaveEnabled = false;//to avoid confirm password does not match problem on save

                var v = db.Users.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    db.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Invalid Request";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }
        public ActionResult Login(loginModel model)
        {
            ViewBag.captchacount = 0.ToString();

            if (model.Username == null || model.Password == null)
            {
            }
            else
            {
                Session["username"] = model.Username.ToString();

                string hashedPassword = LogInOut_ForgPass_Func.GenerateSHA256String(model.Password);
                if (DB.Users.Where(x => x.UserName == model.Username).Where(x => x.State != "Active").FirstOrDefault() != null)
                {
                    ViewBag.message = "User Blocked";
                }
                else if (DB.Users.Where(x => x.UserName == model.Username).Where(x => x.IsEmailVerified == false).FirstOrDefault() != null)
                {
                    ViewBag.message = "User not verified";
                }

                else if (DB.Users.Where(x => x.UserName == model.Username).Where(x => x.Password == hashedPassword).FirstOrDefault() != null)
                {
                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                        1,                        // Ticket version
                        model.Username,           // Username to be associated with this ticket
                        DateTime.Now,             // Date/time ticket was issued
                        DateTime.Now.AddDays(14), // Date and time the cookie will expire
                        false,                    // if user has chcked rememebr me then create persistent cookie
                        model.Username,
                        FormsAuthentication.FormsCookiePath);
                    string encrypted = FormsAuthentication.Encrypt(ticket);
                    var    cooki     = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                    cooki.Expires  = DateTime.Now.AddDays(14);
                    cooki.HttpOnly = true;
                    Response.Cookies.Add(cooki);

                    using (DBentities db = new DBentities())
                    {
                        LogInOut_ForgPass_Func HelperFunc = new LogInOut_ForgPass_Func();
                        User resetCaptcha = HelperFunc.UsernameExists(model.Username);
                        resetCaptcha.CaptchaCounter = 0;
                        db.Users.Attach(resetCaptcha);
                        var ourentry = db.Entry(resetCaptcha);
                        ourentry.Property(e => e.CaptchaCounter).IsModified = true;
                        db.SaveChanges();
                    }
                    return(RedirectToAction("UserDashboard", "Dashboard"));
                }
                else
                {
                    ViewBag.message = "Wrong password";

                    LogInOut_ForgPass_Func HelperFunc = new LogInOut_ForgPass_Func();
                    User LoginUser = HelperFunc.UsernameExists(model.Username);
                    //User LoginUser = (from u in DB.Users
                    //          where u.Email == model.EmailID
                    //          select u).FirstOrDefault();
                    if (LoginUser != null)
                    {
                        LoginUser.CaptchaCounter++;
                        ViewBag.captchacount = LoginUser.CaptchaCounter.ToString();
                        DB.Users.Attach(LoginUser);
                        var entry = DB.Entry(LoginUser);
                        entry.Property(e => e.CaptchaCounter).IsModified = true;
                        // other changed properties
                        DB.SaveChanges();
                        if (LoginUser.CaptchaCounter > 3)
                        {
                            return(RedirectToAction("Captcha"));
                        }
                    }
                    else
                    {
                        ViewBag.message = "Wrong username or password";
                    }
                }
            }
            return(View());
        }