Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Need to encrypt the password in file.

by chandantul (Beadle)
on Jan 05, 2021 at 00:25 UTC ( #11126323=perlquestion: print w/replies, xml ) Need Help??

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

Hello All, I have placed a constant password in file but i will need to encypt the constant password in 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 file.

Replies are listed 'Best First'.
Re: Need to encrypt the password in file.
by hippo (Chancellor) on Jan 05, 2021 at 09:33 UTC
Re: Need to encrypt the password in file.
by kcott (Bishop) 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 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 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 file.
by xavier8854 (Novice) on Jan 06, 2021 at 16:28 UTC


    I think that will achive your goal.



      I think that 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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11126323]
Approved by jcb
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2021-04-14 14:36 GMT
Find Nodes?
    Voting Booth?

    No recent polls found