Re: Properties files to read the tokes and passwords outside of the perl scripts.
by salva (Canon) on Dec 14, 2020 at 07:30 UTC
|
The CPAN module Config::Properties allows one to read Java property files. Its documentation contains example code. | [reply] |
|
open my $fh, '<', "C:/" . "conf.prop" or die "unable to open configura
+tion file";
my $properties = Config::Properties->new();
$properties->load($fh);
my $value = $properties->getProperty('my.token');
This might help somebody. Simple question with simple answers.Thanks | [reply] [d/l] |
Re: Properties files to read the tokes and passwords outside of the perl scripts.
by GrandFather (Saint) on Dec 14, 2020 at 04:36 UTC
|
These days it is unusual to store passwords. Most often cryptographic hashes of passwords are stored and compared against hashes calculated for candidate passwords. This may not apply to your situation, but you haven't told us what that is. Maybe if you tell us more about the problem you are trying to solve we can give a better answer?
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
| [reply] |
|
These days it is unusual to store passwords.
I read the question differently to you GrandFather - I took it that the OP wants to store passwords that they want to use rather than check. Something like a password that the script needs to connect to a database or similar.
Does this difference of understanding come from a badly asked question?
| [reply] |
|
| [reply] |
Re: Properties files to read the tokes and passwords outside of the perl scripts.
by haukex (Archbishop) on Dec 14, 2020 at 08:26 UTC
|
There are lots of different ways to do this. JSON, YAML, XML, INI (simpler), .properties as mentioned by salva, even Perl (/shameless plug), and many more (see e.g. the Config:: namespace on CPAN). As for locating the files in the filesystem, there's also lots of ways to do this. Hardcoded paths (e.g. in /etc or perhaps /usr/local/etc), paths relative to the script's location via FindBin plus File::Spec or e.g. Path::Class for filename manipulations, having the config in the user's $HOME ($ENV{HOME} in Perl), in Windows via the registry, passing the config filename on the command line or in an environment variable, something as simple as the current working directory, or for example if you're running inside Docker, Docker secrets.
Update: Expanded the lists above a little bit.
| [reply] [d/l] [select] |
Re: Properties files to read the tokes and passwords outside of the perl scripts.
by stevieb (Canon) on Dec 14, 2020 at 05:54 UTC
|
"Can you please share an example code for the same?"
This is your challenge, not ours. This site is not a free code writing service.
Post what you've completed so far, and ask questions on the part that doesn't work. You'll learn nothing if you simply expect people to do all of your work for you. That may seem harsh, but it's reality, and a valuable lesson.
| [reply] |
Re: Properties files to read the tokes and passwords outside of the perl scripts.
by perlfan (Vicar) on Dec 14, 2020 at 19:42 UTC
|
No matter what you store in a file, make sure the file with the secrets is properly set to be read only by the effective user (i.e., chmod 600). Another thing to note is that setting an environmental variable explicitly in the parent process using the information in this file will allow child processes to extract the password without require the child to re-read the file or have to pass it via commandline argument (which will show your password in the process list). | [reply] [d/l] |