Hi all,

What I am trying to do is to verify a password from a Web form send with CHAP.
The password is send in md5_hex and is formed in this way with Java Script:

document.formname.password.value = hexMD5('\027' + document.formname.p +assword.value + '\340\174\012\314\214\070\070\231\377\005\016\132\270 +\024\241\163');

When I 'alert' in JavaScript the upper string, I see that \340 and other are actually displayed as UTF characters.

For the Upper example with password 'AAA' the result is:
18ed4d4f656255182e771016deb7d23a
But in Perl I can not generate the same md5 in almost no way.

For example:
#!/usr/bin/perl use strict; use Digest::MD5; #Example 1==================== my $chapid = "\027"; my $chapchalange = "\340\174\012\314\214\070\070\231\377\005\016\132\2 +70\024\241\163"; print "\nExample1=". Digest::MD5::md5_hex($chapid."AAA".$chapchalange) +; #Example2===================== my $chapid2= '\027'; my $chapchalange2= '\340\174\012\314\214\070\070\231\377\005\016\132\2 +70\024\241\163'; print "\nExample2=".Digest::MD5::md5_hex($chapid2."AAA".$chapchalange2 +);

The result is:
Example1=18ed4d4f656255182e771016deb7d23a Example2=3f40ad10610755cefd8223a3a1a566db
As you can see in Example2 the values are not interpreted as utf-8 chars and this mess the md5 sum.
The other thing I have noticed is that when I dump the upper string with use 'Devel::Peek qw(Dump);' the result is:
Example1= ------------------------ SV = PV(0x80120d070) at 0x801269f18 REFCNT = 1 FLAGS = (PADTMP,POK,pPOK) PV = 0x801209f58 "\27AAA\340|\n\314\21488\231\377\5\16Z\270\24\241s" +\0 CUR = 20 LEN = 24 ------------------------------ Example2= ------------------------------- SV = PV(0x80120d650) at 0x8012c5810 REFCNT = 1 FLAGS = (PADTMP,POK,pPOK) PV = 0x80124ec58 "\\027AAA\\340\\174\\012\\314\\214\\070\\070\\231\\ +377\\005\\016\\132\\270\\024\\241\\163"\0 CUR = 71 LEN = 72
And I see no utf8 flag for the internal representation?
So back to my real example I receive this chapid, chapchalange and password through CGI. This is what I get as CGI params as result of CGI::Vars();
{ 'username' => 'Ptestuser', 'password' => '18ed4d4f656255182e771016deb7d23a', 'chap-id' => '\\027', 'chap-challenge' => '\\340\\174\\012\\314\\214\\070\\070\\23 +1\\377\\005\\016\\132\\270\\024\\241\\163', };
I try almost everything I have found in internet about reading utf-8 CGI params, and nothing help. I try:
------------------- Encode::decode('UTF-8'...); ------------------- utf8::decode(); ------------------- binmode STDIN, ":encoding(utf8)"; ------------------- use CGI qw( -utf8 ); ------------ use Encode qw(decode); use URI::Escape::XS qw(decodeURIComponent); $_ = decode('UTF-8', decodeURIComponent($_), Encode::FB_CROAK); ------------- s{%([a-fA-F0-9]{2})}{ pack ("C", hex ($1)) }eg; # Kept from existin +g code s{%u([0-9A-F]{4})}{ pack ('U*', hex ($1)) }eg; # Added utf8::decode $_; --------------- and many others

Currently I see no way to verify the password.
I must say that the encoding of the HTML page is windows-1251 and so is the encoding of my Perl environment (CP1251).
Any help will be appreciated as I have already lost almost 2 days on this peace of code.
Thanks in advance,
Kaloyan Iliev

In reply to Perl CGI UTF8 AND CHAP PASSWORD VERIFICATION by kaloyan_iliev

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.