chandantul has asked for the wisdom of the Perl Monks concerning the following question:

Hello All, I have placed a constant password in config.properties file but i will need to encypt the constant password in config.properties but the password will be read from my PERL code. Do we have any solution on this?

  • Comment on Need to encrypt the password in config.properties file.

Replies are listed 'Best First'.
Re: Need to encrypt the password in config.properties file.
by hippo (Archbishop) on Jan 05, 2021 at 09:33 UTC
Re: Need to encrypt the password in config.properties file.
by kcott (Archbishop) on Jan 05, 2021 at 03:32 UTC

    G'day chandantul,

    It's unclear exactly what you are doing, so I can only give a general answer.

    Firstly, don't store plain-text passwords. When a password is set (or changed) pass it through a hashing algorithm (or similar) and store the result. Subsequently, when a user presents a password for authentication, pass that through the same algorithm and compare the result with what's already stored: if they're the same, grant access; if different, deny access.

    Both perlfaq8 and perlfaq9 have information about passwords.

    You should probably also look into the various algorithms available, whether you are going to ensure users use strong passwords, how often the passwords need to be changed, how many failed access attempts are allowed before account suspension, and so on. It's a big topic and your question, as I said, can only attract a general answer.

    — Ken

Re: Need to encrypt the password in config.properties file.
by shmem (Chancellor) on Jan 05, 2021 at 00:49 UTC

    Your requirements aren't clear. See I know what I mean. Why don't you?
    We can try to find solutions only for stated problems. If the password is encrypted, perl will read the encrypted password from the config file. Where's the problem?

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re: Need to encrypt the password in config.properties file.
by jcb (Parson) on Jan 05, 2021 at 00:39 UTC

    What you are asking is fundamentally not possible. If the script can decrypt the password, so can anyone with access to the script, by examining the script to obtain the key.

    At best, you can obfuscate the stored password. I suggest MIME::Base64 for that.

Re: Need to encrypt the password in config.properties file.
by xavier8854 (Novice) on Jan 06, 2021 at 16:28 UTC

    Hi,

    I think that https://metacpan.org/pod/GnuPG will achive your goal.

    Cheers,

    Xavier

      I think that https://metacpan.org/pod/GnuPG will achive your goal.

      and where will the password / private key be saved? in the script?

A reply falls below the community's threshold of quality. You may see it by logging in.