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

Hi, I am working on a tacacs project. i need to search for a user and change his passwords which is in a file. like cat tac_plus.conf user = godknows { default service = deny member = l1admins login = des password enable = des password } how can i accomplish this please help. I am new to perl, hence do forgive me if this is a basic question. the script which is being as asked is i need to verify the user, if exists in the file, then run the command tac_pwd, allow the user to enter the pwd, the encrypted pasword output from the tac_pwd needs to be taken and replaced in the tac_plus.conf file. Please do let me how i can accomplish this again sorry if this is a very basic question. I am new and will learn fast with little from you

Replies are listed 'Best First'.
Re: replacing password in a file
by marinersk (Priest) on May 13, 2015 at 15:55 UTC

    To add a bit to toolic's note, which is spot on by the way, the point is that here in the Monastary we tend to prefer you show some dedication to the task.

    Being new to Perl is fine -- but if you're at the "I might want to use Perl for this task but have never touched Perl" stage, then your homework is to get started first, prove you can write and run at least the most basic of Perl scripts, and show some sense of comprehending how to use a programming language to accomplish tasks.

    Then, even the simplest of context-specific questions are a joy for us to help you along your path through the gardens of Perl.

      Nice work marinersk,

      It seems we need your comments more than ever. ++ for well done and said!

      Regards...Ed

      "Well done is better than well said." - Benjamin Franklin

Re: replacing password in a file
by toolic (Bishop) on May 13, 2015 at 14:35 UTC
    • Read perlintro.
    • Write some code.
    • Post your code here in code tags if you have specific questions.
Re: replacing password in a file
by GotToBTru (Prior) on May 13, 2015 at 17:00 UTC

    This is a very basic Perl question, concerning replacing one value in a file with another. You will find many such questions here - some even this week. That should be enough to get you started.

    Your problem is only slightly complicated because you need to deal with encrypted passwords. You will need to find out what method is used (MD5? SHA? DES?), and locate the Perl module that will perform that function. Search CPAN here to find them. Perl has the crypt() function that uses DES, so you may not need a special module.

    Dum Spiro Spero
      Perl has the crypt() function that uses DES

      Are you sure? All documentation I found just states that crypt() calls crypt() in the C library. And that function in the C library is free to choose any algorithm. Maybe crypt() in your perl on your computer uses DES. But that is just how the C library on your computer is implemented. On other computers, the C library may use a different algorithm, perhaps even choose one of a few depending on some external configuration.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        My copy of "The Perl 5 Programmer's Reference" says it uses DES. It's from 1997. Next time I'll double check with perldoc.

        Dum Spiro Spero