コード例 #1
0
        public IActionResult Recover(int id, int passwordId)
        {
            var password     = _db.Passwds.Where(a => a.Id == passwordId).FirstOrDefault();
            var passToUpdate = _db.PasswdHistories.Where(a => a.Id == id).FirstOrDefault();

            if (password.UserId == Functions.getUser(_cache).Id)
            {
                PasswdHistory passwdHistory = new PasswdHistory()
                {
                    NewPasswd = passToUpdate.OldPasswd,
                    OldPasswd = password.Password,
                    Time      = DateTime.Now,
                    UserId    = password.UserId,
                    PasswdId  = password.Id
                };
                Functions.AddHistoryToDatabase(_db, passwdHistory);

                password.Password = passToUpdate.OldPasswd;


                _db.SaveChanges(); // save database
                return(RedirectToAction("Index"));
            }
            _cache.Set(CacheNames.error4, "You are not the owner");
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public IActionResult Edit()
        {
            var password = _db.Passwds.Where(a => a.Id == Passwd.Id).FirstOrDefault();

            if (password.UserId == Functions.getUser(_cache).Id)
            {
                if (ModelState.IsValid)
                {
                    var oldPassword    = password.Password;
                    var masterPassword = _cache.Get(CacheNames.masterPassword).ToString();         // get current user masterpassword
                    var encrypted      = AESHelper.EncryptString(Passwd.Password, masterPassword); // encrypt with masterpassword
                    password.Password   = Convert.ToBase64String(encrypted);                       // add encypted password as a string to variable
                    password.WebAddress = Passwd.WebAddress;
                    password.Login      = Passwd.Login;

                    ActionType actionType = new ActionType()
                    {
                        Action = "Edit password id=" + password.Id,
                        UserId = password.UserId,
                        Time   = DateTime.Now
                    };
                    Functions.AddActionToDatabase(_db, actionType);

                    PasswdHistory passwdHistory = new PasswdHistory()
                    {
                        NewPasswd = password.Password,
                        OldPasswd = oldPassword,
                        Time      = DateTime.Now,
                        UserId    = password.UserId,
                        PasswdId  = password.Id
                    };


                    Functions.AddHistoryToDatabase(_db, passwdHistory);

                    _db.SaveChanges(); // save database
                    return(RedirectToAction("Index"));
                }
                return(View(Passwd));
            }
            _cache.Set(CacheNames.error4, "You are not the owner");
            return(RedirectToAction("Index"));
        }
コード例 #3
0
ファイル: Functions.cs プロジェクト: jezo90/PasswordWallet
 public static void AddHistoryToDatabase(ApplicationDbContext db, PasswdHistory passwdHistory)
 {
     db.PasswdHistories.Add(passwdHistory);
     db.SaveChanges();
 }