예제 #1
0
        /// <summary>
        /// Changes the file/directory's password
        /// </summary>
        public void ChangePassword()
        {
            // Get new password
            SecureString newPassword = GetPassword.GetPasswordFromCMD(askText: "Enter the new password: ");

            Password.Clear();

            Password = newPassword;
        }
예제 #2
0
        /// <summary>
        /// Creates a file locker and immediately locks <paramref name="file"/>
        /// </summary>
        /// <param name="file">The file to lock/unlock</param>
        /// <param name="timeTillDeath">the time until the file automatically locks itself</param>
        public Locker(List <string> file, long timeTillDeath, bool shouldChangePass = false)
        {
            TimeTillDeath = timeTillDeath;
            Files         = GetAllFiles.GetAllFilesFromPaths(file);
            Password      = GetPassword.GetPasswordFromCMD();
            // start new line from GetPasswordFromCMD()
            Console.WriteLine();

            for (int i = 0; i < file.Count(); i++)
            {
                var f = file[i];

                // if the file is already locked
                if (Path.GetExtension(f) == ".lock")
                {
                    // let File be the original file name without .lock
                    Files[i] = f.Remove(f.Length - 5);
                    try
                    {
                        UnlockFile(f, Files[i]);
                    }
                    catch (CryptographicException)
                    {
                        Console.WriteLine("Password is incorrect.");
                        File.Delete(Files[i]);
                        Environment.Exit(1);
                    }
                }
            }

            // in case of ctrl-c, lock the file
            Console.CancelKeyPress += new ConsoleCancelEventHandler(HandleConsoleEnd);

            if (shouldChangePass)
            {
                ChangePassword();
            }
            else
            {
                // wait until timer dies
                Thread.Sleep((int)TimeTillDeath);
            }
        }