/// <summary>
        /// Delete a specify connection
        /// </summary>
        /// <param name="tmpConnectionToSet">connection to delete</param>
        internal void DeleteConnection(ConnectionModel tmpConnectionToSet)
        {
            BCEngine engine = new BCEngine(new AesEngine(), Encoding.UTF8);

            engine.SetPadding(new Pkcs7Padding());

            string encComputerMacAddress = engine.Encrypt(string.Concat(Salt, tmpConnectionToSet.MachineMacAddress, Pepper), Key256Bits);
            string encComputerName       = engine.Encrypt(string.Concat(Salt, tmpConnectionToSet.MachineName, Pepper), Key256Bits);
            string encComputerUserName   = engine.Encrypt(string.Concat(Salt, tmpConnectionToSet.MachineUserName, Pepper), Key256Bits);

            using (PasswordKeeperEntities context = new PasswordKeeperEntities())
            {
                // Delete any previous row which match
                List <ConnectionTemp> existingConnections = (from conn in context.ConnectionTemps
                                                             where conn.ComputerMacAddress.Equals(encComputerMacAddress) &&
                                                             conn.ComputerName.Equals(encComputerName) &&
                                                             conn.ComputerUserName.Equals(encComputerUserName)
                                                             select conn).ToList();

                if (existingConnections.Count > 0)
                {
                    context.ConnectionTemps.RemoveRange(existingConnections);
                    context.SaveChanges();
                }
            }
        }
        /// <summary>
        /// Add a custom field for a password
        /// </summary>
        /// <param name="fieldType">Type of the custom field</param>
        /// <param name="pwdId">Password id</param>
        /// <param name="webControlId">Id of the HTML control</param>
        internal void AddOrUpdateCustomField(Tools.TypeField fieldType, int pwdId, string webControlId)
        {
            using (PasswordKeeperEntities context = new PasswordKeeperEntities())
            {
                CustomField cField = (from field in context.CustomFields
                                      where field.IdPassword == pwdId && field.IdCustomFieldType == (int)fieldType
                                      select field).FirstOrDefault();

                if (cField == null)
                {
                    cField = new CustomField()
                    {
                        IdCustomFieldType = Convert.ToInt32(fieldType),
                        IdPassword        = pwdId,
                        ControlId         = webControlId
                    };

                    context.CustomFields.Add(cField);
                }
                else
                {
                    cField.ControlId = webControlId;
                }

                context.SaveChanges();
            }
        }
        /// <summary>
        /// Delete a password
        /// </summary>
        /// <param name="pwdId">Password id</param>
        internal void Delete(int pwdId)
        {
            using (PasswordKeeperEntities context = new PasswordKeeperEntities())
            {
                Password pass = GetPassword(context, pwdId);

                pass.IsActive = false;

                context.SaveChanges();
            }
        }
示例#4
0
        /// <summary>
        /// Delete a user
        /// </summary>
        /// <param name="userId">User id</param>
        internal void Delete(int userId)
        {
            using (PasswordKeeperEntities context = new PasswordKeeperEntities())
            {
                User userToDelete = GetUser(context, userId);

                userToDelete.IsActive = false;

                context.SaveChanges();
            }
        }
        /// <summary>
        /// Delete all custom fields stored for a password
        /// </summary>
        /// <param name="pwdId">Password Id</param>
        internal void Delete(int pwdId)
        {
            using (PasswordKeeperEntities context = new PasswordKeeperEntities())
            {
                IEnumerable <CustomField> cFields = from field in context.CustomFields
                                                    where field.IdPassword == pwdId
                                                    select field;

                cFields.ToList().ForEach(field => context.CustomFields.Remove(field));

                context.SaveChanges();
            }
        }
        /// <summary>
        /// Clean all connections
        /// </summary>
        internal void SwipeOldConnections()
        {
            using (PasswordKeeperEntities context = new PasswordKeeperEntities())
            {
                // Delete any previous row older than an hour
                List <ConnectionTemp> existingConnections = (from conn in context.ConnectionTemps
                                                             where DbFunctions.AddHours(conn.ConnexionDate, 1) < DateTime.Now
                                                             select conn).ToList();

                if (existingConnections.Count > 0)
                {
                    context.ConnectionTemps.RemoveRange(existingConnections);
                    context.SaveChanges();
                }
            }
        }
示例#7
0
        /// <summary>
        /// Update existing user
        /// </summary>
        /// <param name="userToUpdate">User to update</param>
        internal void Update(UserModel userToUpdate)
        {
            PasswordHasher hasher = new PasswordHasher();

            string passwordHash = hasher.Hash(string.Concat(Salt, userToUpdate.Password, Pepper));

            using (PasswordKeeperEntities context = new PasswordKeeperEntities())
            {
                User currentUser = GetUser(context, userToUpdate.Id);

                currentUser.PasswordHash = passwordHash;
                currentUser.DisplayName  = userToUpdate.DisplayName;

                context.SaveChanges();
            }
        }
        /// <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();
            }
        }
示例#9
0
        /// <summary>
        /// Create new user
        /// </summary>
        /// <param name="userToCreate">User to create</param>
        internal void Create(UserModel userToCreate)
        {
            using (PasswordKeeperEntities context = new PasswordKeeperEntities())
            {
                PasswordHasher hasher = new PasswordHasher();

                string passwordHash = hasher.Hash(string.Concat(Salt, userToCreate.Password, Pepper));

                User newUser = new User()
                {
                    Login        = userToCreate.Login,
                    PasswordHash = passwordHash,
                    DisplayName  = userToCreate.DisplayName,
                    CreationDate = userToCreate.CreationDate,
                    IsActive     = userToCreate.IsActive
                };

                context.Users.Add(newUser);
                context.SaveChanges();
            }
        }
        /// <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();
            }
        }