示例#1
0
        public ActionResult SharePasswordDatail(SharePasswordKey sharePasswordKey)
        {
            var sharedPassword = dbContext.GetSharedPasswordByHash(sharePasswordKey.KeyHash);

            try
            {
                sharedPassword.PasswordHash =
                    EncryptionHelper.DecryptPasswordAES(
                        sharedPassword.PasswordHash,
                        sharePasswordKey.Key
                        );

                if (ValidateDecryptedPassword(sharedPassword.PasswordHash))
                {
                    throw new Exception();
                }

                HttpContext.Session.SetString(
                    "WarningMessage",
                    ""
                    );

                return(View("SharedPasswordDetails", sharedPassword));
            }
            catch
            {
                HttpContext.Session.SetString(
                    "WarningMessage",
                    "Wrong sharing key!"
                    );

                return(RedirectToAction(nameof(Index)));
            }
        }
        public void SharePassword(SharePasswordKey sharePasswordKey)
        {
            var shareInfo   = GetPasswordShareInfo();
            var userInfo    = GetUserInfo();
            var passToShare = dbContext.GetPassword(shareInfo.PasswordId);

            dbContext.CreateSharedPassword(
                new SharedPassword()
            {
                Login        = passToShare.Login,
                PasswordHash = ChangePasswordHash(
                    passToShare.PasswordHash,
                    userInfo.LoggedUserPassword,
                    sharePasswordKey.KeyHash),
                SharedForUser = sharePasswordKey.SharedForUser,
                OwnerId       = shareInfo.OwnerId,
                WebAddress    = passToShare.WebAddress,
                Description   = passToShare.Description
            });

            ActivityLog.Log(
                userInfo.Id,
                ActionType.SharePassword,
                dbContext);
        }
        public int CreateSharePasswordKey(SharePasswordKey sharePasswordKey)
        {
            string sqlQuery = "Insert Into SharePasswordKey " +
                              "(PasswordId, SharedForUser, OwnerId, KeyHash) " +
                              "Values(@PasswordId, @SharedForUser, @OwnerId, @KeyHash)";

            return(db.Execute(sqlQuery, sharePasswordKey));
        }
        private void DeleteRelatedSharedPassword(SharePasswordKey sharePasswordKey)
        {
            var userInfo = GetUserInfo();
            var password = dbContext.GetPassword(sharePasswordKey.PasswordId);

            var decryptedPass =
                EncryptionHelper.DecryptPasswordAES(
                    password.PasswordHash,
                    userInfo.LoggedUserPassword);

            var sharedPasswordHash = EncryptionHelper.EncryptPasswordAES(
                decryptedPass,
                EncryptionHelper.DecryptPasswordAES(
                    sharePasswordKey.KeyHash,
                    userInfo.LoggedUserPassword));

            dbContext.DeleteSharedPasswordByHash(sharedPasswordHash);
        }
        public ActionResult Create(SharePasswordKey sharePasswordKey)
        {
            try
            {
                var shareInfo = GetPasswordShareInfo();

                SharePassword(sharePasswordKey);

                sharePasswordKey.OwnerId    = shareInfo.OwnerId;
                sharePasswordKey.PasswordId = shareInfo.PasswordId;
                sharePasswordKey.KeyHash    = EncryptionHelper.EncryptPasswordAES(
                    sharePasswordKey.KeyHash,
                    GetUserInfo().LoggedUserPassword);

                dbContext.CreateSharePasswordKey(sharePasswordKey);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }