The following code replaces a password hash within configuration file - it replaces it with a newly generated hash.

Random hash is generated by the passgen() function.

This hash seems to be somehow wrong, it is different from the hash generated natively without using passgen()

problem:
print md5_hex(&passgen); != print md5_hex("same_string");

- System: Linux I would be really appreciate if anyone could suggest a working solution.

use strict; use warnings; use Tie::File; use Digest::MD5 qw(md5_hex); my @array; my $email='email@address.com'; tie @array, 'Tie::File', 'webpass.set' or die "$!"; foreach my $line (@array) { my ($user,$pass,$rest,$seed); if ($line=~/$email/ig){ ($user,$pass,$rest)=split(/::{1,10}/,$line,3); $seed=passgen(); #chomp $seed; $pass=md5_hex($seed); $line=$user."::".$pass."::".$rest; print $line; print "\nChanged \n"; print "\n\nNew Password:",&passgen; exit 0; } } print "sry - your email has not been found!\n\n"; sub passgen { my ($random_string, $char, @chars, $ret ); @chars=qw(a b c d e f); foreach (1..7) { $random_string.= $chars[rand @chars]; } return $random_string; }
Solved - thanks

20080109 Janitored by Corion: Restored content, as per Writeup Formatting Tips


In reply to Md5 hash gen - [solved] by karavay

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.