Recent

Author Topic: Password Protected Files  (Read 1015 times)

Badger

  • Jr. Member
  • **
  • Posts: 85
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

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

I'm using Windows 10 Lazarus v2.0.8

eljo

  • Sr. Member
  • ****
  • Posts: 408
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: 258
  • 'The knowledge is the key.'
    • FPCProjectShare
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!
Check my ProjectShare site and share your content: FPCShare

Jake012345

  • Sr. Member
  • ****
  • Posts: 258
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Password Protected Files
« Reply #3 on: July 12, 2020, 03:53:54 am »
Here's my solution:
Check my ProjectShare site and share your content: FPCShare

Badger

  • Jr. Member
  • **
  • Posts: 85
Re: Password Protected Files
« Reply #4 on: July 12, 2020, 10:53:39 am »
Thanks.  I'll give it a try.
Badger

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

I'm using Windows 10 Lazarus v2.0.8

Jake012345

  • Sr. Member
  • ****
  • Posts: 258
  • 'The knowledge is the key.'
    • FPCProjectShare
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.
Check my ProjectShare site and share your content: FPCShare

ASBzone

  • Sr. Member
  • ****
  • Posts: 461
  • Automation leads to relaxation...
    • Free BrainWaveCC Console Utilities
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.0.11 r63516 / FPC v3.2.1-r46879 (via FpcUpDeluxe) -- Windows 64-bit install w/32-bit cross-compile
Primary System: Windows 10 Pro x64, Version 2004 (Build 19041.508)
Other Systems: Windows 10 Pro x64, Version 2004 or greater

Warfley

  • Sr. Member
  • ****
  • Posts: 303
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

  • New Member
  • *
  • Posts: 48
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.
Laz 2.0.8
Linux-Mint 20.04.0 + Cinnamon, Kernel 5.8 (NOT stock Ubuntu/Mint 5.4 Kernel)
Lenovo Flex 5 Ryzen 5 4500, 512GB-NVMe, 16GB memory

Badger

  • Jr. Member
  • **
  • Posts: 85
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

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

I'm using Windows 10 Lazarus v2.0.8

ASBzone

  • Sr. Member
  • ****
  • Posts: 461
  • Automation leads to relaxation...
    • Free BrainWaveCC Console Utilities
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.0.11 r63516 / FPC v3.2.1-r46879 (via FpcUpDeluxe) -- Windows 64-bit install w/32-bit cross-compile
Primary System: Windows 10 Pro x64, Version 2004 (Build 19041.508)
Other Systems: Windows 10 Pro x64, Version 2004 or greater

 

TinyPortal © 2005-2018