/// <summary>
        /// Update a password
        /// </summary>
        /// <param name="pwdToUpdate">Password to update</param>
        internal void Update(PasswordModel pwdToUpdate)
        {
            BCEngine engine = new BCEngine(new AesEngine(), Encoding.UTF8);

            engine.SetPadding(new Pkcs7Padding());

            using (PasswordKeeperEntities context = new PasswordKeeperEntities())
            {
                Password pass = GetPassword(context, pwdToUpdate.Id);

                pass.DisplayName = pwdToUpdate.DisplayName;
                pass.Login       = engine.Encrypt(string.Concat(Salt, pwdToUpdate.Login, Pepper), Key256Bits);
                pass.Password1   = engine.Encrypt(string.Concat(Salt, pwdToUpdate.Password, Pepper), Key256Bits);
                pass.Url         = engine.Encrypt(string.Concat(Salt, pwdToUpdate.Url, Pepper), Key256Bits);
                pass.Notes       = engine.Encrypt(string.Concat(Salt, pwdToUpdate.Notes, Pepper), Key256Bits);

                context.SaveChanges();
            }
        }
예제 #2
0
        /// <summary>
        /// Map controls fields into password object
        /// </summary>
        private void MapFieldsToObject()
        {
            if (Passwd == null)
            {
                Passwd = new PasswordModel()
                {
                    CreationDate = DateTime.Now,
                    IsActive     = true,
                    UserId       = UserId,
                    Key          = PasswordKey
                };
            }

            Passwd.DisplayName = txtDisplayName.Text.Trim();
            Passwd.Login       = txtUserName.Text.Trim();
            Passwd.Password    = txtPassword.Text;
            Passwd.Url         = txtUrl.Text.Trim();
            Passwd.Notes       = txtNotes.Text.Trim();
        }
        /// <summary>
        /// Create a new password
        /// </summary>
        /// <param name="pwdToCreate">Password to create</param>
        internal void Create(PasswordModel pwdToCreate)
        {
            BCEngine engine = new BCEngine(new AesEngine(), Encoding.UTF8);

            engine.SetPadding(new Pkcs7Padding());

            using (PasswordKeeperEntities context = new PasswordKeeperEntities())
            {
                Password newPwd = new Password()
                {
                    Login        = engine.Encrypt(string.Concat(Salt, pwdToCreate.Login, Pepper), Key256Bits),
                    Password1    = engine.Encrypt(string.Concat(Salt, pwdToCreate.Password, Pepper), Key256Bits),
                    DisplayName  = pwdToCreate.DisplayName,
                    Url          = engine.Encrypt(string.Concat(Salt, pwdToCreate.Url, Pepper), Key256Bits),
                    Notes        = engine.Encrypt(string.Concat(Salt, pwdToCreate.Notes, Pepper), Key256Bits),
                    CreationDate = pwdToCreate.CreationDate,
                    IsActive     = pwdToCreate.IsActive,
                    UserId       = pwdToCreate.UserId
                };

                context.Passwords.Add(newPwd);
                context.SaveChanges();
            }
        }
예제 #4
0
 public frmPasswordManagement(Tools.PasswordAction typeOfAction, int usrId, string key, PasswordModel password) : this(typeOfAction, usrId, key)
 {
     Passwd = password;
 }