Recent

Author Topic: Password Protected Files  (Read 2298 times)

Badger

  • Full Member
  • ***
  • Posts: 144
Password Protected Files
« on: May 25, 2020, 01:09:13 pm »
Not sure if this should be posted here or if it should be directed to Free pascal but here goes.

I have a project that is running from a Directory and it frequently opens and saves to a number of files in a sub directory.  It would be a real problem if someone using the same computer corrupted the files either by accident or on purpose. 

What I'd like to do is protect the sub folder with a password that the program could supply when loading or saving files so the user was not aware of the need for a password.

Is this possible?
Badger
(A bad tempered, grumpy animal that sleeps most of the winter!)

If at first you don't succeed - you're running about average!

I'm using Windows 10 Lazarus v2.4.4  FPC 3.2.2   Win 32/64

eljo

  • Sr. Member
  • ****
  • Posts: 468
Re: Password Protected Files
« Reply #1 on: May 25, 2020, 01:30:43 pm »
Not sure if this should be posted here or if it should be directed to Free pascal but here goes.

I have a project that is running from a Directory and it frequently opens and saves to a number of files in a sub directory.  It would be a real problem if someone using the same computer corrupted the files either by accident or on purpose. 

What I'd like to do is protect the sub folder with a password that the program could supply when loading or saving files so the user was not aware of the need for a password.

Is this possible?
Not nativelly  no.  Create a user  in the system change the access rights of the directory to block everyone else out except the user you created. Use something like runas inernally (thread or com based on windows) to execute your program under the new user account to allow access to the directory for your program only.

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Password Protected Files
« Reply #2 on: May 25, 2020, 08:14:36 pm »
Maybe Useless!


Little bit complicated...
So you can make a program what starts on startup and auto load in all files in the folder.
And now the files are unmodifiable until the program runs. (On the OnClose action, you can make a restart procedure (for the task manager))
The Reader application can send data for this application to motivate that to makes the current file free.

I hope it can be worked!

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Password Protected Files
« Reply #3 on: July 12, 2020, 03:53:54 am »
Here's my solution:

Badger

  • Full Member
  • ***
  • Posts: 144
Re: Password Protected Files
« Reply #4 on: July 12, 2020, 10:53:39 am »
Thanks.  I'll give it a try.
Badger
(A bad tempered, grumpy animal that sleeps most of the winter!)

If at first you don't succeed - you're running about average!

I'm using Windows 10 Lazarus v2.4.4  FPC 3.2.2   Win 32/64

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Password Protected Files
« Reply #5 on: July 12, 2020, 11:06:33 am »
And here's with parameter compatibility!

You can start it with parameters param1=folderpath param2=shutdown passwword

You can add it to autostart programs and start it with parameters, in the background.

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: Password Protected Files
« Reply #6 on: July 12, 2020, 02:25:50 pm »
Not sure if this should be posted here or if it should be directed to Free pascal but here goes.

I have a project that is running from a Directory and it frequently opens and saves to a number of files in a sub directory.  It would be a real problem if someone using the same computer corrupted the files either by accident or on purpose. 

What I'd like to do is protect the sub folder with a password that the program could supply when loading or saving files so the user was not aware of the need for a password.

Is this possible?


What operating system is this intended to run on?
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

Warfley

  • Hero Member
  • *****
  • Posts: 1499
Re: Password Protected Files
« Reply #7 on: July 12, 2020, 02:52:37 pm »
I've posted here three approaches to a similar problem.

The whole denying file access does not really work (as admin you can always kill a process), and even if, it only works for windows.

Variant number one (from my post) is pretty simple (lazarus can create zip archives and with dcpcrypt you can easily encrypt them, probably around 20 lines of code should be enough), and should be more than enough to protect your files
« Last Edit: July 12, 2020, 02:54:21 pm by Warfley »

QEnnay

  • Full Member
  • ***
  • Posts: 115
Re: Password Protected Files
« Reply #8 on: July 12, 2020, 05:52:53 pm »
Why don't you just encrypt the data being written?

Use the "OnGetText" to read it back in and decrypt. I do it all the time.

Use the old TurboPascal Lockbox (I think that is what I use, can't check at the moement) Component for encryption.
Linux-Mint 20.1 x64 + Cinnamon; Lenovo Flex 5 Ryzen 5 4500, 16GB memory
FPC: 3.2.0-1, Lazarus 2.0.12-0, all 64bit

Badger

  • Full Member
  • ***
  • Posts: 144
Re: Password Protected Files
« Reply #9 on: July 13, 2020, 12:04:02 am »
Quote
What operating system is this intended to run on?
Cross Platform

Quote
Why don't you just encrypt the data being written?
I'm more interested in preventing accidental, or deliberate, changing of the files.  I guess it's very unlikely - maybe I'm worrying too much.
Badger
(A bad tempered, grumpy animal that sleeps most of the winter!)

If at first you don't succeed - you're running about average!

I'm using Windows 10 Lazarus v2.4.4  FPC 3.2.2   Win 32/64

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: Password Protected Files
« Reply #10 on: July 13, 2020, 03:49:23 am »
Quote
What operating system is this intended to run on?
Cross Platform

Quote
Why don't you just encrypt the data being written?
I'm more interested in preventing accidental, or deliberate, changing of the files.  I guess it's very unlikely - maybe I'm worrying too much.

Cross-platform will be a little trickier.  You'll probably have to IFDEF your way through this one.

Can you elaborate on the type of issue you are looking to address?  Real world scenarios.

It *might* be that you are worrying too much, but the scenarios will help.    If the files are available for a long time, then perhaps it makes sense, but if they are transitory, then...

If there is that much concern, better to run the app in a specific user context, and have it write to folders granting it only the permission needed.

In most OSes, it wouldn't be too difficult at all to create a random credential, and use it for access to the location in question.

But it sure feels like this is a solution in search of a problem.       

If you put an exclusive lock on the files you are using, nothing else will be able to touch them.

And, as several folks have pointed out, any person with admin access AND local access, will ultimately be able to access those files.    All you can do is slow them down, or hope they are not too serious.
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

 

TinyPortal © 2005-2018