Problem with function "crypt"

Discussion in 'Perl Misc' started by madan, Jul 22, 2006.

  1. madan

    madan Guest

    hi all,
    i have a problem when using the function "crypt" in my code...

    i want to encrypt a password when a user enters his password in the
    textfield..

    i wrote a simple code which will be called by itself and accept the
    password..encrypt it and displays the ecrypted one and again asks for
    another password..

    Problem is that it is showing the same result for what ever text i
    enter..i am using perl 5.6..

    this code is working when tried in console(without CGI)...but when used
    CGI i get the error...

    the code is as below...
    ***********************************************************************************
    #! c:\perl\bin\perl
    use strict;
    use CGI;
    use CGI::Carp 'fatalsToBrowser';

    my($cgi,$element,%passlist,$encrypted_password,$password);
    $cgi=CGI->new;

    print $cgi->header;
    print $cgi->start_html;

    foreach $element ($cgi->param)
    {
    $passlist{$element} = $cgi->param($element);
    }

    print "<form action=\"/cgi-bin/sample/encrypt.pl\">";

    if($passlist{'gave'})
    {
    ($encrypted_password) = &encrypt_text($password);
    print "<br>the password you entered has been encrypted to
    :$encrypted_password";
    }

    print "<br>Enter your password";
    print "<br><input type=text name=\"pword\">";
    print "<br><input type=submit value=\"Submit\">";
    print "<input type=hidden name=\"gave\" value=\"true\">";

    sub encrypt_text
    {
    my($text)=(@_);
    my ($test,$encrypted_text);
    $test = length($text).$text;
    $text = length($text).$text;
    $encrypted_text = crypt($text,$test);
    return $encrypted_text;
    }
    ****************************************************************************
    thanks in advance
    with regards
    madan
    madan, Jul 22, 2006
    #1
    1. Advertising

  2. madan

    Guest

    madan wrote:

    > hi all,
    > i have a problem when using the function "crypt" in my code...
    >


    >
    > Problem is that it is showing the same result for what ever text i
    > enter..i am using perl 5.6..
    >



    > use strict;


    use warnings;
    use CGI::Carp qw/fatalsToBrowser/;

    The above lines would have tipped you off to the uninitialized value
    warnings.

    > use CGI;
    > use CGI::Carp 'fatalsToBrowser';
    >
    > my($cgi,$element,%passlist,$encrypted_password,$password);


    You declare $password here, but then you never assign anything to it in
    the following lines of code.

    > $cgi=CGI->new;
    >
    > print $cgi->header;
    > print $cgi->start_html;
    >
    > foreach $element ($cgi->param)
    > {
    > $passlist{$element} = $cgi->param($element);
    > }
    >
    > print "<form action=\"/cgi-bin/sample/encrypt.pl\">";
    >
    > if($passlist{'gave'})
    > {
    > ($encrypted_password) = &encrypt_text($password);


    And now you call encrypt_text every time with an undefined value, so
    it's not surprising that you always get the same encrypted value back
    (and the sub call doesn't need the special feature that appending an
    '&' in front of it results in, so you shouldn't use one).

    Matt
    , Jul 22, 2006
    #2
    1. Advertising

  3. madan

    Dr.Ruud Guest

    schreef:
    > madan:


    >> use strict;

    >
    > use warnings;
    > use CGI::Carp qw/fatalsToBrowser/;


    Maybe news: applies here too:

    <quote>
    Often overlooked, the warningsToBrowser call must be invoked too or
    the buffer won't be flushed, eg,

    use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
    print header();
    warningsToBrowser(1);
    </quote>

    --
    Affijn, Ruud

    "Gewoon is een tijger."
    Dr.Ruud, Jul 22, 2006
    #3
  4. madan

    Guest

    Dr.Ruud wrote:

    > schreef:
    > > madan:

    >
    > >> use strict;

    > >
    > > use warnings;
    > > use CGI::Carp qw/fatalsToBrowser/;

    >
    > Maybe news: applies here too:
    >
    > <quote>
    > Often overlooked, the warningsToBrowser call must be invoked too or
    > the buffer won't be flushed, eg,
    >
    > use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
    > print header();
    > warningsToBrowser(1);
    > </quote>
    >


    Yes, and a particularly bad oversight on my part since he'd already put
    the fatalsToBrowser call in and that's what I was responding to... : (

    Matt
    , Jul 22, 2006
    #4
  5. madan

    madan Guest

    thanks all for ur reply and support....the main thing i did wrong is
    that i never used $password...i have to place the parameter as an
    argument that was passed to the script in the calling function...now i
    am getting unique encrypted values for the password i entered....
    thanks again

    with regards
    madan chowdary
    madan, Jul 24, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AdrianK
    Replies:
    0
    Views:
    1,533
    AdrianK
    Jul 9, 2003
  2. Marco Herrn

    more secure crypt() function

    Marco Herrn, Oct 4, 2003, in forum: Python
    Replies:
    3
    Views:
    355
    Marco Herrn
    Oct 4, 2003
  3. luca72

    python glibc crypt() function

    luca72, Apr 20, 2010, in forum: Python
    Replies:
    9
    Views:
    1,332
    geremy condra
    Apr 21, 2010
  4. Cosmia Luna
    Replies:
    4
    Views:
    324
    Cosmia Luna
    Mar 11, 2012
  5. asg

    de-crypt... crypt

    asg, Dec 23, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    125
Loading...

Share This Page